Skip to main content

array.slice(startIndex, endIndex)

Creates a new sub-array from an array

Availability

Device + Agent

Parameters

Name Type Description
startIndex Integer Index of the first item to be added to the sub-array
endIndex Integer Optional index after the last item to be added to the sub-array

Returns

Array

Description

This method copies a series of array items into a new array and returns it. It takes the index of the first item to be copied from the source array into the new one as its first parameter. Squirrel continues copying items from this point onward until it either reaches the end of the source array or reaches the optionally specified end index, passed as a second parameter. The item with the same index as the end value is not copied.

Example Code