length()

← Back to documentation


Description

Returns the number of elements in an array.

Syntax

length(array)

Parameters

Return Value

Number (integer) - the array size

Examples

Basic usage

arr = [1, 2, 3, 4, 5]
print(length(arr))
# Output: 5

Empty array

empty = []
print(length(empty))
# Output: 0

Using in a loop

arr = [10, 20, 30, 40]
i = 0
while (i < length(arr)) {
    print(arr[i])
    i = i + 1
}
# Output:
# 10
# 20
# 30
# 40

Array of strings

names = ["Alice", "Bob", "Charlie"]
print(length(names))
# Output: 3

Error: not an array

length(42)
# Error: Function length expects array, got: number

See Also


© 2026 elliktronic · Jaf Language