array.slice()

Create an Array from the elements of another Array.

Signature

slice(start: Int, end: Int) => Array<T>

Description

The slice() method creates an Array from the calling Array by copying the Array elements from the start index, inclusive, up to the end index, exclusive.

Parameters

Parameter Type Required Description

start

Int

Yes

Zero-based Array element index to start copying, inclusive. A negative start counts from Array element zero.

end

Int

Zero-based Array element index to end copying, exclusive. When end is larger than the Array length, all elements are copied from start to the last Array element. If end is less than or equal to start, an empty Array is returned.

Return value

Type Description

Array

Array with elements from the start index to the end index, inclusive, of the calling Array.

Examples

Create an Array of the second and third elements of the calling Array:

[1, 2, 3, 4, 5].slice(1,3)
[
  2,
  3
]

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!