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.


array.unshift(item1, item2, ..., itemX)

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.

<!DOCTYPE html> 
        var arr1 = ["A", "B", "C", "D"]; 
        arr1.unshift("X", "Y");




JavaScript unshift Method array

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

Note: The 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.