push() and pop() methods used to add and remove the elements of the Array. These mehtods operate on the end of the Array.
USING PUSH
var friends = ["Rekha", "chandra"] friends.push("Sastry"); alert(friends);
OUTPUT: ======== Rekha,chandra,Sastry It adds the value at the end of the array.
USING POP. The pop() method removes the last element and returns the element that is removed.
var friends =["Rekha",chandra","Sastry"]; var res = friends.pop(); alert(res);
OUTPUT: ====== Sastry
NOTE:Now the length of the array is decremented by 1.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|