javascript

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

var items = ["Apple", "Banana", "Orange"];
items.unshift("Papaya", "Watermelon");
console.log(items);
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?