...

View Full Version : The Array.splice() Method



pilau
05-04-2007, 03: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 />');
}
</scr

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

Syntax
arrayObject.splice(index,howmany,element1,.....,elementX)

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum