Collection.prototype.slice()

Return a new collection having a range of the original.

Syntax

collection.slice(from int) Collection collection.slice(from int, to int) Collection

Parameters

from int

Starting index, inclusive

to int

Ending index, exclusive. So if ending index is 3, only files up to index 2 will be included in the new collection.

Description

Return a new collection having files between a starting and ending index or the original collection. Negative indexes mean distance from the end of the collection.

Note that the starting index is inclusive, the ending index is exclusive. If you are a mathematician, let’s just say it returns the range [from, to[.

Examples

Creating an empty slice, original is unchanged.

Slicing a range.

Only providing a starting index.

Using negative indexes.

Last 2 files of the collection using negative indexes.

Subscribe to our newsletter!