http://www.w3school.com.cn/jsref/jsref_shift.aspDefinition and Usage
The shift () method removes the first element from the array and returns the value of the first element.
Grammar
Arrayobject.shift ()
return value
The value of the original first element of the array.
Description
If the array is empty, then the shift () method will not take any action, returning the undefined value. Note that the method does not create a new array, but instead modifies the original arrayobject directly.
Hints and notes
Note: This method will change the length of the array.
Tip: To delete and return the last element of the array, use the Pop () method.
Example
In this example, we will create an array and delete the first element of the array. Note that this will also change the length of the array:
<script type= "Text/javascript" >var arr = new Array (3) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" Document.writ E (arr + "<br/>") document.write ( arr.shift() + "<br/>") document.write (arr) </script>
Output:
George,john,thomasgeorgejohn,thomas
tiy
- Shift ()
- How to use Shift () to delete and return the first element of an array.
JavaScript Shift () method