Quirrel4.41.0

types.Table.values

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

Returns an array of every value in the table.

examples/types/table/values-basic.nut
let squad = {hitPoints = 100}
println("squad.values() =", ", ".join(squad.values().map(@(v) v.tostring())))
Output:
squad.values() = 100

Return 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

examples/types/table/values.nut
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: true

See also

keysReturns an array of every key 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