unshift Function:
Adds one or more elements to the beginning of an array and returns the new length of the array.
Syntax:
arrayname.unshift(element1,element2.........elementn)
Example in HEAD section:
<html> <head> <title>unshift Function</title> <script language="javascript"> var nushifted; myArray = ["angel", "clown"]; document.writeln("myArray before: " + myArray + "<p>"); unshifted = myArray.unshift("mandarin", "surgeon"); document.writeln("myArray after: " + myArray + "<p>"); </script> </head> </html> |
Example in BODY section:
<html> <head> <title>unshift Function</title> </head> <body> <script language="javascript"> var nushifted; myArray = ["angel", "clown"]; document.writeln("myArray before: " + myArray + "<p>"); unshifted = myArray.unshift("mandarin", "surgeon"); document.writeln("myArray after: " + myArray + "<p>"); </script> </body> </html> |
OUTPUT
myArray before: angel,clown
myArray after: angel,clown,mandarin,surgeon
No comments:
Post a Comment