Saturday, April 25, 2009

How to insert array elements

Three of the Array class methods--push(), unshift(), and splice()--allow you to insert elements into an array.

The push() method appends one or more elements to the end of an array. In other words, the last element inserted into the array using the push() method will have the highest index number.

The unshift() method inserts one or more elements at the beginning of an array, which is always at index number 0.

The splice() method will insert any number of items at a specified index in the array.

No comments:

Post a Comment