JavaScript Methods | interactive
☰
back to Array methods
JavaScript Array
unshift() method
adds new elements to the beginning of an array
unshift() method adds new elements to the beginning of an array.
syntax ↴
unshift(element1, element2, ..., elementN) ↴
element1, …, elementN The elements to add to the front of the array.
unshift() method changes the original array.
unshift() method changes the length of the array.
unshift() method returns the new length.
syntax 1 description
add new element to the beginning of myArray
↴
myArray.unshift(element1)
syntax 2 description
add new elements (more than 1) to the beginning of myArray
↴
myArray.unshift(element1, element2, ..., elementN)