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:

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
Examples

Expression$head.concat($middle,$tail)

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
Examples

Expression: $myarray.filter(x => x > 5)

where $myarray is a normal array

Result: A new array containing numbers greater than five.


To remove duplicate entries in an array:

Expression$myarray.filter((item, pos, a) => a.indexOf(item) == pos)

where $myarray is a normal array containing ["Fred", "Wilma", "Fred", "Betty", "Fred", "Barney"]

Result: A new array containing [Fred, Wilma, Betty, Barney].

Downloads

find

DescriptionReturns the first element found for which the given callback returns true.
This is similar to the JavaScript Array.find() method.
Syntax
Examples

Expression: $myarray.find(x => x > 5)

where $myarray is a normal array

Result: The first element whose value is greater than five.

findIndex

DescriptionReturns 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
Examples

Expression: $myarray.findIndex(x => x > 5)

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
Examples

Expression: $Array.indexOf(0)

where $Array contains [0, 2, 4, 6, 8]

Result: 0


Expression: $Array.indexOf(1)

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
Examples

Expression: $first.lastIndexOf(0)

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
Examples

Expression: $array.length

Result: A number.

join

Description

Joins all elements of an array into a string.

This is similar to the JavaScript join.

Syntax

where optseparator is an optional string to separate the elements. If omitted, a comma is used.

Examples

Expression: ["SnapLogic", "Data", "Integration"].join(" ")

Result: the string SnapLogic Data Integration

map

Description

Returns a new array with the values transformed by the given callback.
This is similar to the JavaScript Array.map() method.

Syntax
Examples

Expression: $myarray.map(x => x * 10)

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
Examples

Expression: $Array.pop()

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
Examples

Expression: $Array.push("Mobile", "Email")

Result: Mobile and Email will be added to that array and the new length of the array is returned.

reduce

DescriptionReduces 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
Examples

Expression: $myarray.reduce((accum, currentValue) => accum + currentValue, 0)

where $myarray is an array

Result: The sum of all of the elements in the array.

reduceRight

DescriptionLike the reduce() method, except the elements are traversed right-to-left instead of left-to-right.
This is similar to the JavaScript Array.reduceRight() method.
Syntax
Examples

Expression: $myarray.reduceRight((accum, currentValue) => accum + currentValue, "")

where $myarray is an array

Result: Builds a string of the elements in reverse order.

reverse

Description

Transposes the elements of the calling array object in place, mutating the array, and returning a reference to the array.

This is similar to the JavaScript reverse.

Syntax
Examples

Expression: $Array.reverse

Result: Returns the array in reverse order.

shift

Description

Removes the first element from an array and returns that element. This method changes the length of the array.

This is similar to the JavaScript shift.

Syntax
Examples

Expression: $Array.shift()

Result: The first element from an array.

slice

Description

Returns a shallow copy of an array containing copies of the original elements.

This is similar to the JavaScript slice.

Syntax
Examples

Expression: $Array.slice(1,3)

where $Array contains [0, 2, 4, 6, 8]

Result: [2,4]

sort

Description

Returns a sorted array.

This is similar to the JavaScript sort.

Syntax
Examples

Expression: $Array.sort()

Result: A sorted array.

splice

Description

Lets you remove and insert elements in an array and returns an array containing the elements removed

This is similar to the JavaScript splice.

Syntax

where:

  • begin is the index where to start changing the array
  • digit is the number of items to remove
  • item is the items to insert
Examples

For an array, $Contacts, defined as:


Expression: $Contacts.splice(2,0,'Business')

Result: Removes nothing, but inserts "Business" after "Last".


Expression: $Contacts.splice(4,1,'State')

Result: Removes "Zip", inserts "State", returns "Zip" in the output view.

toObject

Description

Performs arrow functions on the values of the array to generate the key/value pair in the object returned by the callback, and, if given, a second callback.

Syntax
Examples

Expression: [1,2,3,4].toObject(x => x, x => x * x)

Result: {“1”:1, “2”:4, “3”:9, “4”:16}


Expression: ['zero', 'one', 'two'].toObject((x, index) => index, x => x.contains('two'))
Result: {"0": false, "1": false, "2": true}

toString

Description

Returns one string containing each array element separated by commas.

This is similar to the JavaScript toString.

Syntax
Examples

Expression: $Array.toString()

Result: Returns a string containing a comma-separated list of the array elements.

Uint8Array.Of

Description

Creates a new Uint8 array from a variable number of arguments.

This is similar to the JavaScript TypedArray.of().

Syntax
Examples

Expression: Uint8Array.Of()

Result: [ 0 ]

Creates an empty array.


Expression: Uint8Array.of(1,2,3,4)

Result: [ 1, 2, 3, 4 ]

Uint8Array.subarray()

Description

Returns a new subarray from an Uint8 array, where the arguments are the indexes begin and end offsets.

This is similar to the JavaScript TypedArray.subarray().

Syntax
Examples

ExpressionUint8Array.subarray (1,3)

Where Uint8Array is [1, 2, 3, 4]

Result[2, 3]

Uint8Array.indexOf()

Description

Returns the first index at which a given element is present. If the element is not present, the result is -1. 

This is similar to the JavaScript TypedArray.indexOf().

Syntax
Examples

Expressionuint8.indexOf(8)

Where Uint8Array is [1, 2, 3, 4, 5]

Result: -1

Expression: uint8.indexOf(3)

Where Uint8Array is [1, 2, 3, 4, 5, 6, 7, 8]

Result: 2

Uint8Array.lastindex.Of()

Description

Returns the last index at which a given element is present. If the element is not present, the result is -1.

This is similar to the JavaScript lastIndexOf().

Syntax
Examples

ExpressionUint8Array.lastindexOf(30)

Where Uint8 is [10, 20, 30, 40, 50, 60]

Result: 4

ExpressionUint8Array.lastindexOf(48)

Where Uint8 is [12, 24, 48, 96]

Result: 2


unshift

Description

Adds the specified elements to the beginning of an array and returns the new length of the array.

This is similar to the JavaScript unshift.

Syntax
Examples

Expression: $Contacts.unshift('Title')

Result: Adds "Title" to the beginning of the array and returns the new array length.