Skip to content

arrayLength - Get number of elements in an array

arrayLength gets the number of elements in a given array.

Syntax

Like many functions in DataPrime, arrayLength supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

arrayLength(array: array<any>): number          
array: array<any>.arrayLength(array: array<any>): number

Arguments

NameTypeRequiredDescription
arrayarray of type anytrueThe array to test

Example - Find out how many jobs are waiting

Consider the following document:

{
    "loading_jobs_waiting": ["loading_job1", "loading_job2", "loading_job3"]
}

If we wish to know how many loading jobs are waiting to be executed, we can use arrayLength:

create waiting_jobs from arrayLength(loading_jobs_waiting)
create waiting_jobs from loading_jobs_waiting.arrayLength()

This results in the following document:

{
    "loading_jobs_waiting": ["loading_job1", "loading_job2", "loading_job3"],
    "waiting_jobs": 3
}