Array Operators
Array transformation, filtering, and aggregation operators.
map - Transform Array
Transforms each element in an array using a logic expression.
Syntax
{"map": [array, logic]}
Parameters
- array (array): Array to transform
- logic (expression): Logic to apply to each element (use
{"var": ""}for current element)
Return Type
Array - Transformed array
Examples
Double each number:
// Data: {"numbers": [1, 2, 3, 4, 5]}
{"map": [
{"var": "numbers"},
{"*": [{"var": ""}, 2]}
]}
// → [2, 4, 6, 8, 10]
Extract property:
// Data: {"users": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]}
{"map": [
{"var": "users"},
{"var": "name"}
]}
// → ["Alice", "Bob"]
Format strings:
{"map": [
[1, 2, 3],
{"cat": ["Item ", {"var": ""}]}
]}
// → ["Item 1", "Item 2", "Item 3"]
Empty array:
{"map": [[], {"*": [{"var": ""}, 2]}]} // → []
filter - Filter Array
Filters array elements based on a condition.
Syntax
{"filter": [array, logic]}
Parameters
- array (array): Array to filter
- logic (expression): Condition to test each element
Return Type
Array - Filtered array containing only elements where condition is truthy
Examples
Filter even numbers:
// Data: {"numbers": [1, 2, 3, 4, 5, 6]}
{"filter": [
{"var": "numbers"},
{"==": [{"%": [{"var": ""}, 2]}, 0]}
]}
// → [2, 4, 6]
Filter by property:
// Data: {"users": [
// {"name": "Alice", "active": true},
// {"name": "Bob", "active": false},
// {"name": "Charlie", "active": true}
// ]}
{"filter": [
{"var": "users"},
{"var": "active"}
]}
// → [{"name": "Alice", "active": true}, {"name": "Charlie", "active": true}]
Filter by comparison:
{"filter": [
{"var": "scores"},
{">": [{"var": ""}, 70]}
]}
reduce - Reduce Array
Reduces an array to a single value using an accumulator.
Syntax
{"reduce": [array, logic, initial]}
Parameters
- array (array): Array to reduce
- logic (expression): Logic with
accumulatorandcurrentvariables - initial (any): Initial accumulator value
Return Type
Any - Final accumulated value
Examples
Sum all numbers:
// Data: {"numbers": [1, 2, 3, 4, 5]}
{"reduce": [
{"var": "numbers"},
{"+": [{"var": "accumulator"}, {"var": "current"}]},
0
]}
// → 15
Find maximum:
{"reduce": [
{"var": "numbers"},
{"if": [
{">": [{"var": "current"}, {"var": "accumulator"}]},
{"var": "current"},
{"var": "accumulator"}
]},
0
]}
Concatenate strings:
{"reduce": [
["a", "b", "c"],
{"cat": [{"var": "accumulator"}, ",", {"var": "current"}]},
""
]}
// → ",a,b,c" (note leading comma)
Count occurrences:
{"reduce": [
{"var": "items"},
{"+": [
{"var": "accumulator"},
{"if": [{"==": [{"var": "current"}, "target"]}, 1, 0]}
]},
0
]}
all - All Elements Match
Tests if all elements satisfy a condition.
Syntax
{"all": [array, logic]}
Parameters
- array (array): Array to test
- logic (expression): Condition to test
Return Type
Boolean - true if all elements match, false otherwise
Examples
All positive:
{"all": [
[1, 2, 3, 4, 5],
{">": [{"var": ""}, 0]}
]}
// → true
All even:
{"all": [
[2, 4, 6, 8],
{"==": [{"%": [{"var": ""}, 2]}, 0]}
]}
// → true
Empty array:
{"all": [[], {">": [{"var": ""}, 0]}]} // → true (vacuously true)
All users active:
{"all": [
{"var": "users"},
{"var": "active"}
]}
some - Some Elements Match
Tests if at least one element satisfies a condition.
Syntax
{"some": [array, logic]}
Parameters
- array (array): Array to test
- logic (expression): Condition to test
Return Type
Boolean - true if any element matches, false otherwise
Examples
Has negative:
{"some": [
[1, -2, 3, 4],
{"<": [{"var": ""}, 0]}
]}
// → true
Has active user:
{"some": [
{"var": "users"},
{"var": "active"}
]}
Empty array:
{"some": [[], {">": [{"var": ""}, 0]}]} // → false
none - No Elements Match
Tests if no elements satisfy a condition.
Syntax
{"none": [array, logic]}
Parameters
- array (array): Array to test
- logic (expression): Condition to test
Return Type
Boolean - true if no elements match, false otherwise
Examples
No negatives:
{"none": [
[1, 2, 3, 4, 5],
{"<": [{"var": ""}, 0]}
]}
// → true
No inactive users:
{"none": [
{"var": "users"},
{"!": {"var": "active"}}
]}
Empty array:
{"none": [[], {">": [{"var": ""}, 0]}]} // → true
merge - Merge Arrays
Flattens and merges multiple arrays into one.
Syntax
{"merge": [array1, array2, ...]}
Parameters
- arrays (array): Arrays to merge
Return Type
Array - Single merged array
Examples
Basic merge:
{"merge": [[1, 2], [3, 4], [5]]} // → [1, 2, 3, 4, 5]
Mixed types:
{"merge": [["a", "b"], [1, 2], [true, null]]}
// → ["a", "b", 1, 2, true, null]
Combine data sources:
{"merge": [
{"var": "localItems"},
{"var": "remoteItems"}
]}
in - Contains Value
Checks if a value exists in an array or substring in a string.
Syntax
{"in": [value, array_or_string]}
Parameters
- value (any): Value to search for
-
array_or_string (array string): Array or string to search in
Return Type
Boolean - true if found, false otherwise
Examples
Value in array:
{"in": [3, [1, 2, 3, 4, 5]]} // → true
{"in": [6, [1, 2, 3, 4, 5]]} // → false
Substring in string:
{"in": ["world", "hello world"]} // → true
{"in": ["foo", "hello world"]} // → false
Check membership:
{"in": [
{"var": "userRole"},
["admin", "moderator", "editor"]
]}
sum / SUM - Sum Array
Sums numeric values in an array, with optional field extraction and threshold.
Syntax
{"sum": [array]}
{"sum": [array, field]}
{"sum": [array, field, threshold]}
{"SUM": [array]}
Parameters
- array (array): Array to sum (or single number)
- field (string, optional): Field name to extract from objects
- threshold (number, optional): Index threshold for stopping
Return Type
Number - Sum of values
Examples
Sum numbers:
{"sum": [[1, 2, 3, 4, 5]]} // → 15
{"SUM": [[10, 20, 30]]} // → 60
Sum object field:
// Data: {"items": [{"price": 10}, {"price": 20}, {"price": 30}]}
{"sum": [{"var": "items"}, "price"]} // → 60
With threshold:
// Sum first 3 elements only
{"sum": [[1, 2, 3, 4, 5], null, 3]} // → 6
Sum variable:
{"sum": [{"var": "values"}]}
for / FOR - Loop and Build Array
Creates an array by iterating from start to end.
Syntax
{"FOR": [start, end, logic]}
Parameters
- start (number): Starting value (inclusive)
- end (number): Ending value (inclusive)
- logic (expression): Logic for each iteration (use
{"var": "$iteration"})
Return Type
Array - Array of results
Examples
Generate range:
{"FOR": [1, 5, {"var": "$iteration"}]}
// → [1, 2, 3, 4, 5]
Generate squares:
{"FOR": [
1,
5,
{"*": [{"var": "$iteration"}, {"var": "$iteration"}]}
]}
// → [1, 4, 9, 16, 25]
Generate labels:
{"FOR": [
0,
3,
{"cat": ["Item ", {"var": "$iteration"}]}
]}
// → ["Item 0", "Item 1", "Item 2", "Item 3"]
Build table rows:
{"FOR": [
1,
10,
{"*": [{"var": "basePrice"}, {"var": "$iteration"}]}
]}
multiplies / MULTIPLIES - Flatten and Multiply
Flattens nested arrays and multiplies all numeric values.
Syntax
{"multiplies": [value1, value2, ...]}
{"MULTIPLIES": [value1, value2, ...]}
Parameters
- values (array): Values or arrays to flatten and multiply
Return Type
Number - Product of all flattened values
Examples
Multiply flat values:
{"multiplies": [2, 3, 4]} // → 24
Multiply nested arrays:
{"MULTIPLIES": [[2, 3], [4, 5]]} // → 120 (2*3*4*5)
divides / DIVIDES - Flatten and Divide
Flattens nested arrays and divides values sequentially.
Syntax
{"divides": [value1, value2, ...]}
{"DIVIDES": [value1, value2, ...]}
Parameters
- values (array): Values or arrays to flatten and divide
Return Type
Number - Result of sequential division
Examples
Divide values:
{"divides": [100, 2, 5]} // → 10 (100/2/5)
Divide nested:
{"DIVIDES": [[100], [2, 5]]} // → 10
Complex Examples
Calculate Average
{"/": [
{"reduce": [
{"var": "numbers"},
{"+": [{"var": "accumulator"}, {"var": "current"}]},
0
]},
{"length": {"var": "numbers"}}
]}
Filter and Transform
{"map": [
{"filter": [
{"var": "users"},
{"var": "active"}
]},
{"var": "name"}
]}
// Get names of active users
Group By Count
{"reduce": [
{"var": "items"},
{"+": [
{"var": "accumulator"},
{"if": [
{"==": [{"var": "current.category"}, "A"]},
1,
0
]}
]},
0
]}
Find First Match
{"reduce": [
{"var": "users"},
{"if": [
{"!=": [{"var": "accumulator"}, null]},
{"var": "accumulator"},
{"if": [
{"==": [{"var": "current.id"}, {"var": "searchId"}]},
{"var": "current"},
null
]}
]},
null
]}
Validate All Required Fields
{"all": [
["name", "email", "age"],
{"!": {"isempty": {"var": {"var": ""}}}}
]}
Collect Unique Values
{"reduce": [
{"var": "items"},
{"if": [
{"in": [{"var": "current"}, {"var": "accumulator"}]},
{"var": "accumulator"},
{"merge": [{"var": "accumulator"}, [{"var": "current"}]]}
]},
[]
]}
Best Practices
- Use empty string for current element
{"map": [array, {"var": ""}]} - Chain operations for complex transforms
{"map": [ {"filter": [data, condition]}, transform ]} - Use quantifiers instead of reduce when possible
{"all": [array, condition]} // ✓ Clear - Provide initial value for reduce
{"reduce": [array, logic, 0]} // Always specify initial - Handle empty arrays gracefully
{"if": [ {">": [{"length": array}, 0]}, {"map": [array, logic]}, [] ]}
Context Variables
Special variables available in array operations:
{"var": ""}- Current element (map, filter, all, some, none){"var": "accumulator"}- Accumulated value (reduce){"var": "current"}- Current element (reduce){"var": "$iteration"}- Current iteration index (FOR)
Related Operators
- Comparison Operators - For filtering conditions
- Logical Operators - Combine conditions
- Arithmetic Operators - Transform values
- Table Operators - Advanced array queries
Performance Notes
- Short-circuit evaluation in
all,some,none - Zero-copy context switching for current element
- Empty array handling optimized
- Nested array flattening efficient in
merge,multiplies,divides