Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

array.slice()

Get a subset of an Array's elements based on provided indexes.

Signature

slice(from: Number) => Array<A>

slice(from: Number, until: Number) => Array<A>

Description

Creates an Array from the calling Array by copying the Array elements from a provided start index (inclusive) up to the end index (exclusive).

Parameters

Parameter Type Required Description

from

Number

Yes

Zero-based Array element index to start copying (inclusive). Must be an Int. A negative start index counts from Array element zero.

until

Int

Zero-based Array element index to end copying (exclusive). Must be an Int.

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

Return value

Type Description

Array<Generic>

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!