Array II - adding or removing element

It is possible to add or remove elements in array. Follow the example below for more info:

pop() - To remove last element
var cities = ["London", "Reading", "Liverpool", "Manchester", "Basingstoke"];
cities.pop();
alert(cities);

push() - To add element to the last
var cities = ["London", "Reading", "Liverpool", "Manchester", "Basingstoke"];
cities.push("Brighton", "Swansea");
alert(cities);

Share this

Related Posts