shift()

Removes a value from the beginning of a collection, and returns that value.

For a SortedSet, this is equivalent to removing the minimum value of the collection.

For List and Deque, this operation is very fast. For an Array, this operation will require all subsequent values to be shifted to the left to fill the void at index zero.

On collections

Usage

  • shift()

Examples

var list = new List([1, 2, 3]);
list.shift();
list.toArray();
var sortedSet = new SortedSet([11, 8, 5]);
sortedSet.shift();
sortedSet.toArray();

Related

  • unshift(...values)

    Adds values to the beginning of a collection.

  • pop()

    Removes a value from the end of a collection, and returns that value.

  • peek()

    Returns the value at the beginning of a collection, the value that would be returned by shift().