LENGTH

LENGTH returns as an integer the number of items in a collection.

If passed a non-collection, it will throw an error. A collection can be an array, a hash or set, although it is not limited to these.

Function category: Collection

String types are interpreted as collections.

Syntax

LENGTH(arg1)

Arguments

Description

arg1

A collection.

Example

Let's say we're given a response with the following driver information.

{
"data": {
"drivers": [
{
"id": 31225,
"vehicle": "Toyota",
"driver_rating": 9
},
{
"id": 89673,
"vehicle": "BMW",
"driver_rating": 5
},
{
"id": 62744,
"vehicle": "Chrysler",
"driver_rating": 6
}
]
}
}

If we want to find the length of the drivers collection, use the following function.

# Find number of items in collection
LENGTH(data.drivers)
# Returns 3