Quirrel4.41.0

types.Table.keys

Method on every table
pure table.keys(): any

Returns an array of every key in the table.

examples/types/table/keys-basic.nut
let squad = {mvp = "Aria"}
println("squad.keys() =", ", ".join(squad.keys()))
Output:
squad.keys() = mvp

Return value

A new array holding one entry per slot, each the key of that slot.

Notes

Takes no arguments. The order matches the table's current iteration order, which the VM does not guarantee to be stable across runs or seeds - sort the result when the order itself matters, for example before printing it.

keys().len() == t.len() always holds, and calling keys() and values() back to back on the same unchanged table gives corresponding order: keys()[i] is the key for values()[i].

Example

examples/types/table/keys.nut
let t = {a=1, b=2, c=3}
let k = t.keys()
k.sort()               // iteration order is not guaranteed, so sort first
local s = ""
foreach (key in k) s += key
println("keys sorted =", s)
println("k.len() == t.len():", k.len() == t.len())

println("{}.keys().len() =", {}.keys().len())
Output:
keys sorted = abc
k.len() == t.len(): true
{}.keys().len() = 0

See also

valuesReturns an array of every value in the table.
topairsReturns an array of [key, value] pairs, one per slot in the table.
lenReturns the number of key/value pairs in the table.
tableclass index