JavaScript unshift() Method: Array Object
Description
The unshift() method is used to add one or more elements to the beginning of an array and return the length of the array.
Version
Implemented in JavaScript 1.2
Syntax
arrayName.unshift(element1,element2..., elementN)
Parameters
element1,element2,..., elementN
The elements to add to the front of the array.
Example:
In the following web document, unshift() method adds two elements at the beginning of a given array.
HTML Code
JS Code
View the example in the browser
Practice the example online
JavaScript unshift() method exampleSee also:
JavaScript Core objects, methods, properties.
Previous: JavaScript toString() Method: Array Object
Next: JavaScript valueOf() Method: Array Object
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics