JavaScript Array unshift() Method


The JavaScript array unshift() method adds one or more elements in the beginning of the given array and returns the updated array. This method changes the length of the original array.

Javascript array unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

Syntax

array.unshift(item1, item2, ..., itemX)

Example

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.unshift("Lemon","Pineapple");

Example -