Lesson 12 of 15

Tables as Dictionaries

Tables as Dictionaries

Tables can also be used as key-value maps (dictionaries):

local person = {
  name = "Alice",
  age = 30,
  city = "Paris"
}

print(person.name)  -- Alice
print(person.age)   -- 30

Adding & Modifying Fields

person.email = "alice@example.com"
person.age = 31

Bracket Notation

Use brackets for dynamic keys or keys with special characters:

person["full name"] = "Alice Smith"
local key = "city"
print(person[key])  -- Paris

Your Task

Create a table representing a book with title, author, and year, then print each field.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.