types.Table.keys
Method on every
tableReturns an array of every key in the table.
let squad = {mvp = "Aria"}
println("squad.keys() =", ", ".join(squad.keys()))Output:
squad.keys() = mvpReturn 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
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() = 0See also
values | Returns an array of every value in the table. |
topairs | Returns an array of [key, value] pairs, one per slot in the table. |
len | Returns the number of key/value pairs in the table. |
| table | class index |