The push() and pop() methods operate on the end of the array. The shift() and unshift() methods perform the same function as push() and pop(), except in reverse.
The unshift() method adds an element to the beginning of an Array.
var friends = ["Net", "Giri"] friends.unshift("Sastry"); alert(friends);
OUTPUT: Sastry,Net,Giri
Now the shift() which removes an element from the beginning of an Array.
var friends = ["Sastry", "Net", "Giri"] friends.shift(); alert(friends);
OUTPUT: Net,Giri (note friend "Sastry" been removed from the list since we used shift())
|
No responses found. Be the first to respond and make money from revenue sharing program.
|