Here you can find a number of examples on Java Script.Please find the various kinds of examples listed on the right side of this site. If you don't find anything on Java Script then please write to us or leave a commnet. We are pleased to help and find the solution of your problem.
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> |
OUTPUTmyArray before: angel,clown
myArray after: angel,clown,mandarin,surgeon
shift Function:Removes the first element from an array and returns that element. This method changes the length of the array.
Syntax:arrayname.shift()
Example in HEAD section:<html> <head> <title>Shift Function</title> <script language="javascript"> myArray = ["angel", "clown", "mandarin", "surgeon"]; document.writeln("myArray before: " + myArray + "<p>"); shifted = myArray.shift(); document.writeln("myArray after: " + myArray + "<p>"); document.writeln("Removed this element: " + shifted); </script> </head> </html> |
Example in BODY section:<html> <head> <title>Shift Function</title> </head> <body> <script language="javascript"> myArray = ["angel", "clown", "mandarin", "surgeon"]; document.writeln("myArray before: " + myArray + "<p>"); shifted = myArray.shift(); document.writeln("myArray after: " + myArray + "<p>"); document.writeln("Removed this element: " + shifted); </script> </body> </html> |
OUTPUT
myArray before: angel,clown,mandarin,surgeon
myArray after: clown,mandarin,surgeon
Removed this element: angel