shift

Summary

Removes the first element of the array.

Usage

public T+ shift()

Returns

The first element of the array that was removed or undefined if there were no elements in the array.

Description

Removes the first element of the array and returns the element. If there are no elements in the array, undefined is returned.

This method mutates the array.

Examples

Basic Usage
1
2
3
4
5
6
import System;
 
int[] arr = [ 1, 2, 3, 4 ];
Console.log(arr.first()); // 1
arr.shift();              // Removes first element
Console.log(arr.first()); // 2
Return and remove the first element of the array
1
2
3
4
5
6
import System;
 
int[] arr = [ 100, 200, 300, 400];
Console.log(arr.length);   // 4
Console.log(arr.shift());  // 100
Console.log(arr.length);   // 3

Share

HTML | BBCode | Direct Link