Chrome Extension

Add new item at first position of array using unshift() method Javascript

var items = ["Apple", "Banana", "Orange"];
items.unshift("Papaya", "Watermelon");
console.log(items);
We are a bunch of lazy programmers so we developed this chrome extension
search code from your favorite search engine
Install Now
Output
["Papaya", "Watermelon", "Apple", "Banana", "Orange"]

If you want to add a new item to an array at its first position, you can use .unshift() method in javascript. This will insert the items to the very first position of the array. Items are passed as the parameters into unshift() method.

Was this helpful?
0 Comments
Open Code Manager We are hiring