Array Functions and Properties
In this Page
Array Literals
Array literals function similar to JavaScript array literals.
However, extra commas in array literals are not supported.
Example:
["SnapLogic", "Data", "Integration"]
concat
Description | Returns a new array comprised of this array joined with the arrays or values provided as arguments. The concat function also works with Uint8 arrays. This is similar to the JavaScript concat. |
---|---|
Syntax | array.concat(array2,array3...) |
Examples | Expression: Where $head, $middle, and $tail are all arrays. Result: A new array of the target path name containing all three arrays. |
filter
Description | Returns a new array containing only the elements for which the given callback returned true. This is similar to the JavaScript Array.filter() method. |
---|---|
Syntax | array.filter(callback) |
Examples | Expression: where $myarray is a normal array Result: A new array containing numbers greater than five. To remove duplicate entries in an array: Expression: where $myarray is a normal array containing ["Fred", "Wilma", "Fred", "Betty", "Fred", "Barney"] Result: A new array containing [Fred, Wilma, Betty, Barney]. Downloads
|
find
Description | Returns the first element found for which the given callback returns true. This is similar to the JavaScript Array.find() method. |
---|---|
Syntax | array.find(callback) |
Examples | Expression: where $myarray is a normal array Result: The first element whose value is greater than five. |
findIndex
Description | Returns the index of the first element for which the given callback returns true. If no match is found, -1 is returned. This is similar to the JavaScript Array.findIndex() method. |
---|---|
Syntax | array.findIndex(callback) |
Examples | Expression: where $myarray is a normal array Result: The index of the first element whose value is greater than five. |
indexOf
Description | Returns the first index at which a given element can be found in the array or -1 if it is not present. This is similar to the JavaScript indexOf. |
---|---|
Syntax | array.indexOf(element) |
Examples | Expression: where $Array contains [0, 2, 4, 6, 8] Result: 0 Expression: where $Array contains [0, 2, 4, 6, 8] Result: -1 |
lastIndexOf
Description | Returns the last index at which a given element can be found in the array. This is similar to the JavaScript lastIndexOf. |
---|---|
Syntax | array.lastIndexOf(element) |
Examples | Expression: where $first contains [0, 2, 4, 6, 8] Result: 0 |
length
Description | The number of elements in an array. This is similar to the JavaScript length. |
---|---|
Syntax | array.length |
Examples | Expression: Result: A number. |
join
Description | Joins all elements of an array into a string. This is similar to the JavaScript join. |
---|---|
Syntax | array.join(optseparator) where optseparator is an optional string to separate the elements. If omitted, a comma is used. |
Examples | Expression: Result: the string SnapLogic Data Integration |
map
Description | Returns a new array with the values transformed by the given callback. |
---|---|
Syntax | array.map(callback) |
Examples | Expression: where $myarray is an array Result: A new array where the elements have been multiplied by ten. |
pop
Description | Removes the last element from an array and returns that element. This is similar to the JavaScript pop. |
---|---|
Syntax | array.pop() |
Examples | Expression: Result: The last element of the array. |
push
Description | Adds one or more elements to the end of an array and returns the new length of the array. This is similar to the JavaScript push. |
---|---|
Syntax | array.push(element1, ..., elementN) |
Examples | Expression: Result: Mobile and Email will be added to that array and the new length of the array is returned. |
reduce
Description | Reduces an array to a single value using the given callback. For each element in the array, the callback is called with four arguments: the accumulated value (the result from previous calls or the initialValue), the value of the current element, the index of the current element, and the array itself. The exact behavior will change based on whether an initial value is provided. If no value is provided, the callback is called with the first element in the array as the accumulated value and the second element as the current value. If an initial value is provided, then the first call uses the initial value as the accumulated value and the first element as the current value. In general, it is safest to provide an initial value. This is similar to the JavaScript Array.reduce() method. |
---|---|
Syntax | array.reduce(callback, [initialValue]) |
Examples | Expression: where $myarray is an array Result: The sum of all of the elements in the array. |
reduceRight
Description | Like the reduce() method, except the elements are traversed right-to-left instead of left-to-right. This is similar to the JavaScript Array.reduceRight() m |
---|