One of the key features of arrays is that they act like a structure of stacked data.

As always stacked data may have items removed or added to it. The principle the arrays are operated with is called a LIFO (last-in-first-out) stack; meaning that the last item added to an array, is the first to be pushed out.

Two methods are used to add or remove items to an array. These are push() and pop() methods.

The push() method accepts any number of arguments which will be added to an existing array. The pop() method, on the other hand, just removes the last item added to an array.

Consider following examples:

var name = new Array();

name.push("Johnny", "Al", "Igor");

alert(name); // 3 names

name.pop();

alert(name); // 2 names

Example

The example with array stacking methods in JavaScript:

 

›› go to examples ››