types.Table.values
Method on every
tableReturns an array of every value in the table.
let squad = {hitPoints = 100}
println("squad.values() =", ", ".join(squad.values().map(@(v) v.tostring())))Output:
squad.values() = 100Return value
A new array holding one entry per slot, each the value 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 or otherwise post-process the result when the order itself matters.
values().len() == t.len() always holds, and calling keys and values back to back on the same unchanged table gives corresponding order.
Example
let t = {a=1, b=2, c=3}
let v = t.values()
v.sort() // iteration order is not guaranteed, so sort first
local s = ""
foreach (val in v) s += val
println("values sorted =", s)
println("v.len() == t.len():", v.len() == t.len())
// keys() and values() correspond when called back to back
let k = t.keys()
let vals = t.values()
local ok = true
for (local i = 0; i < k.len(); i++)
if (t[k[i]] != vals[i]) ok = false
println("keys/values correspond:", ok)Output:
values sorted = 123
v.len() == t.len(): true
keys/values correspond: trueSee also
keys | Returns an array of every key 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 |