API Reference › Builtin functions › len
function

len

len(x) -> int

Returns the length of its argument: the element count of a slice, or the byte length of a string. Use it to iterate a slice with for index in 0 .. len(items), to check whether a collection is empty, or to compute string slice bounds such as trimming a suffix. It reads the current length, so after you push onto a slice the value it returns grows accordingly. For strings, note it counts bytes, not visual characters.

Parameters

xa slice or string to measure

Example

program CountEnemies {
  handler ReportCount phase Start {
    let wave_sizes = new []int
    push(wave_sizes, 3)
    push(wave_sizes, 5)
    push(wave_sizes, 8)
    print(len(wave_sizes))
  }
}
← All symbols