Removes the first element from an array and returns the removed element. This method changes the length of the array. If used on an empty array, an exception will be thrown.
arrayShift(array)
returns any
array.shift()
Name | Type | Required | Default | Description |
---|---|---|---|---|
array | array | Yes | An array of elements from which the first will be removed and returned. |
Take an array of numbers and shift the first one off.
arr = [ 1, 2, 3 ];
el = arrayShift(arr);
writeOutput( el );
This is the same example as above, but using a member function on the array instead of a standalone function.
arr = [ 1, 2, 3 ];
el = arr.shift();
writeOutput( el );