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?
Similar Posts
- Convert all characters to lowercase using toLowerCase() method in javascript
- Get current year using Javascript Date getFullYear() method
- open link in new tab using javascript
- Array.find() - get the very first element satisfy a condition Javascript
- Remove first n elements from an array using Lodash
- Remove item from array in Javascript
- Test every item of array against some condition in javascript