Javatpoint Logo
Javatpoint Logo

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.

Syntax

The unshift() method is represented by the following syntax:

Parameter

element1,element2,....,elementn - The elements to be added.

Return

The original array with added elements.

JavaScript Array unshift() method example

Let's see some examples of unshift() method.

Example 1

Here, we will add an element in the given array.

Test it Now

Output:

JQuery,AngularJS,Node.js

Example 2

Let's see an example to add more than one elements in the given array.

Test it Now

Output:

Length before invoking unshift(): 2
Length after invoking unshift(): 4
Updated array: JQuery,Bootstrap,AngularJS,Node.js

Next TopicJavaScript Array





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA