isEmpty
Description
Returns true
if the array contains no elements, or false
otherwise.
- Supported element types include
string
,bool
,number
,interval
,timestamp
,regexp
, andenum
.
Syntax
Like many functions in DataPrime, isEmpty
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
array | array | true | The array to check for emptiness |
Example
Use case 1: Check if an array is empty
You can directly test whether an array has any elements:
This produces a new boolean field indicating whether the array is empty.
Use case 2: Optimize execution by skipping work when arrays are empty
Suppose you have documents like the following:
If you want to join names into a string but avoid unnecessary computation for empty arrays, you can combine isEmpty
with an if
statement:
Output
For the above input, the results will look like:
Theme
Light