.unshift()

.unshift()

  • Adds one or more elements to the beginning of an array and returns the new length of the array

  • This method is a mutating method because it changes the original array


Example

const fruits = ["Apple", "Orange", "Grapes"]

fruits.unshift("Peach", "Mango")

console.log(fruits) // Peach, Mango, Apple, Orange, Grapes

JS Bin on jsbin.com