Removing Items from a Javascript Array
The most simple way to remove an item from a Javascript array is by using the "splice()" function. It not only removes the item, but maintains the index position of the newly updated array. This function allows you to define the index position of the element you want to remove, but also allows you to define the range of items to be removed as well.
Example:
var myArray = new Array();
myArray[0] = "Pizza";
myArray[1] = "Cereal";
myArray[2] = "Hot Dog";
To remove the "Cereal" array element, simply do the following
myArray.splice(1, 1);
I found out about this function by reading the following blog:
Comments