Saturday, April 25, 2009

How to remove array elements

Three methods of the Array class--pop(), shift(), and splice()--allow you to remove elements from an array.

The pop() method removes an element from the end of the array. In other words, it removes the element at the highest index number.

The shift() method removes an element from the beginning of the array, which means that it always removes the element at index number 0.

The splice() method, which can also be used to insert elements, removes an arbitrary number of elements starting at the index number specified by the first argument sent to the method.

No comments:

Post a Comment