Menu
Coddy logo textTech

Key-Value Pairs

Part of the Fundamentals section of Coddy's Lua journey — lesson 64 of 90.

A key-value pair is a way of storing information where each piece of data (the value) has a unique name (the key) that identifies it. Think of it like a real dictionary where you look up a word (the key) to find its definition (the value).

local player = {
    ["name"] = "Alex",
    ["level"] = 15,
    ["health"] = 100
}

In this example, "name", "level", and "health" are the keys, while "Alex", 15, and 100 are their corresponding values.

Cheat sheet

A key-value pair stores data where each value has a unique key that identifies it:

local player = {
    ["name"] = "Alex",
    ["level"] = 15,
    ["health"] = 100
}

Keys are "name", "level", "health" and values are "Alex", 15, 100.

Try it yourself

This lesson doesn't include a code challenge.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals