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.

  • arg1 is a collection

Examples

Example 1: Length of a collection

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 our drivers collection, we can use Length:

LENGTH(data.drivers)

This returns the following:

3