Mega Code Archive

 
Categories / JavaScript Tutorial / Array
 

Array unshift()

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>