Click to See Complete Forum and Search --> : How to splice a multidimensional array?


mivate
06-08-2006, 03:50 PM
Hello I have a multiD array and I want to remove one array item from
another inner array..splice works fine for me with just a 1D array..but with the Multi I also get [x][y] has no properties..can someone explain what I am doing wrong pls?

Code is here:

var a = [0,1,2,3,4,5,6,7,8,9];
var b = [
[0,1,2,3],
['a', 'b', 'c']
];

function show(){
alert(a);
}

function editArray(){
show();
a.splice(2, 1);
show();
}

function editArray2(){
alert(b);
b.splice([0][1], 1);
alert(b);
}

A1ien51
06-08-2006, 04:07 PM
I have not tried this, just a guess...

b[0].splice(1, 1);

Eric

mivate
06-08-2006, 07:00 PM
Thanks Eric that worked! :)

David Harrison
06-08-2006, 07:17 PM
Just for future reference, JavaScript does not have multi-dimentional arrays, however, the items in an array can be an array, and the items in that array can also be arrays. Therefore it's possible to mimic a multi-dimentional array, though all the arrays are entirely separate from one another.

phpnovice
06-08-2006, 08:00 PM
...for good people to do evil deeds it takes religion.
<off topic>
Not quite true... It does not take religion for good people to do evil deeds. It takes religion in order to recognize that a person is doing an evil deed. Such recognition falls under the definition of "sin." In addition, "correct" religion also recognizes that no person can be deemed "good" for "all have sinned, and come short of the glory of God." (Romans 3:23)
</off topic>