Key and Value

Tables are so-called associative arrays. That basically means they store values and assign keys to them. If you call a table and give it a key (using square brackets), it gives you the value assigned to that key.

As you can see in the example above, keys can be strings, booleans and numbers. Even if you don’t specify a key, Lua uses a number to index the value.

How to iterate (rummage in) tables using keys and for loops

Using a for loop, you can go trough all index numbers of a table.

There is a method for iterating the entire table using a for loop.