Push and pop in JavaScript

Source code :

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
alert(fruits);
fruits.pop("Orange");
alert(fruits);

Output :

[Banana,Apple]

Algorithm :

  1. Initialize a array with elements
  2. Use the push keyword to insert the new element in array
  3. Use the pop keyword to remove the new element in array
  4. Finally print the result

Output :


                

Comments :