View Full Version : The Array.splice() Method

05-04-2007, 04:06 PM
If I get it right, the splice method only works if all of the indexes in the array are numerical values? (i.e. 0, 1, 2, 3, ...)

I tried using it when the indexes were strings, not numbers - and it didn't work:

var x = new Array();
x['one'] = 'a;
x['two'] = 'b';
x['three'] = 'c';
x['four'] = 'd';

x.splice('two', 1);

for (i in x)
document.write(x[i] + '<br />');

05-04-2007, 04:56 PM
Definition and Usage
The splice() method is used to remove and add new elements to an array.


1) index - Required. Specify where to add/remove elements. Must be a number
2) howmany - Required Specify how many elements should be removed. Must be a number, but can be "0"
3) element1 - Optional. Specify a new element to add to the array
4) elementX - Optional. Several elements can be added