JavaScript unshift Method | adds new items to the beginning of an array

Using JavaScript unshift() method you can add one or more elements to the beginning of the given array. This methods change the length of array by increases the length of the existing array by the number of elements added to the array.

Syntax

Parameter Values

items: Elements to be added at the beginning of the array.

Example of JavaScript unshift Method

Let’s see how to Add new items to the beginning of an array in JS.

Output:

JavaScript unshift Method array

Do comment if you have any doubts, suggestions and questions in this tutorial.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.