ArrayLength()

Summary

Computes the number of elements in an array.

Syntax

len = ArrayLength(array input_array)

Argument Contents
input_array Any array

Returns

An integer containing the number of elements in the array.

Notes

  • ArrayLength() counts the elements in an array regardless of their type. It can be used on arrays whose elements are of mixed type.

  • If the array is null, ArrayLength() returns zero.

  • ArrayLength() counts only the top-level elements in the array. If the array contains sub-arrays, each sub-array is considered one element; ArrayLength() does not count the number of elements in sub-arrays.

Example

// Two ways to get the length of an array...
x = {"Fred", 243.5, {1, 2, 3}, "Last Item"}
l1 = ArrayLength(x) // l1 is equal to 4
l2 = x.length // l2 is equal to 4, too
// Here's a very common type of loop
maps = GetMapNames()
for i = 1 to ArrayLength(maps) do // or, for i = 1 to maps.length
// do something to the map...
end

Error Codes

Error Type Meaning
Error The argument is not an array

See Also

Function Summary
ArrayPosition() Finds the position of a sub-array in an array
Subarray() Extracts a number of elements from an array