Array in JavaScript – unshift() Method

Array unshift() method adds one or more elements to the beginning of an existing array and returns the new length of the array in Javascript.

Syntax is as below:

item1, item2, itemN are elements to add to the front of array.

Return Value:

The return type is number, new length of the array. For IE browser this returns undefined.

Example:

Output: This will result:

Try yourself the unshift() method example above. In this way you can add new array elements at the top of an array in JavaScript.

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.