JavaScript Array shift() Method
- Previous Page reverse()
- Next Page slice()
- Go to the Previous Level JavaScript Array Reference Manual
Definition and Usage
shift()
The method removes the first item of the array.
Note:shift()
The method will change the length of the array.
Note:shift
The return value of the method is the removed item.
Note:shift()
The method will change the original array.
Tip:To delete the last item of the array, please use pop()
Method.
Instance
Example 1
Delete the first item in the array:
var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.shift();
Example 2
Array.shift() returns the removed array element:
const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.shift(); // Returns "Banana"
Syntax
array.shift()
Parameters
No parameters.
Technical Details
Return Value: |
Any type *, indicates the array item that has been removed. * Array items can be strings, numbers, arrays, boolean values, or any other object types allowed in arrays. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
All browsers fully support shift()
Method:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Array
Tutorial:JavaScript Array Const
Tutorial:JavaScript Array Methods
Tutorial:JavaScript Sorting Array
Tutorial:JavaScript Array Iteration
Manual:JavaScript Array push() Method
- Previous Page reverse()
- Next Page slice()
- Go to the Previous Level JavaScript Array Reference Manual