Quirrel4.41.0

types.Table.len

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

Returns the number of key/value pairs in the table.

Return value

A non-negative int: the number of slots currently in the table.

Notes

Takes no arguments. t.len() and t.len(1) differ only in that the second throws wrong number of parameters passed to native closure 'len' (2 passed, 1 required) - the VM checks the count before len ever runs.

Example

examples/types/table/len.nut
let t = {a=1, b=2, c=3}
println("t.len() =", t.len())

t.rawdelete("a")
println("t.len() after rawdelete(\"a\") =", t.len())

let empty = {}
println("empty.len() =", empty.len())

try {
  t.len(1)     // takes no arguments
} catch (e) {
  println("t.len(1) throws:", e)
}
Output:
t.len() = 3
t.len() after rawdelete("a") = 2
empty.len() = 0
t.len(1) throws: wrong number of parameters passed to native closure 'len' (2 passed, 1 required)

See also

keysReturns an array of every key in the table.
valuesReturns an array of every value in the table.
rawinReports whether key is a slot in the table, without calling a metamethod.
tableclass index