How to use array unshift in JavaScript

In this article I am going to explain about unshift method in JavaScript.
  • 2267

Array unshift method in JavaScript

The array unshift method is used to inserting element in the starting position.

Syntax of unshift method


Parameters in unshift method:

  • element

    The element to add front of array.

Return value of  unshift  method

unshift  method returns the length of new array.

Example of unshift method

<!DOCTYPE html>



<script type="text/javascript">

    var val = new Array("one", "two", "three", "four");


    var length = val.unshift("First");

    document.write("Now array is : " + val);

    document.write("<br /> Length of the array is : " + length);




Ask Your Question 
Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.