Array.unshift() : unshift « Array « JavaScript Tutorial






Syntax

array.unshift(arg1,...argN)

The unshift() method adds the arguments to the front of the array as new elements.

Existing elements are shifted up to allow room for the new elements.

arg1,...argN are elements to be added to the array

It returns the length of the array after adding the new elements.

The following example adds elements to the Front of an Array Using the unshift() Method.

<html>
    <script language="JavaScript">
    <!--
    grades = new Array(9,8);
    newLength = grades.unshift(10,2);

    for(i=0; i<newLength; i++)
    {
      document.write("grades[",i,"]=",grades[i],"<br>");
    }
    -->
    </script>
</html>








11.35.unshift
11.35.1.Array.unshift()
11.35.2.Add element to the begin of an array by using Array.unshift
11.35.3.Array.unshift() returns new length
11.35.4.Using unshift method from zArray Library