PDA

View Full Version : Please help me cut from array


Renton
02-09-2002, 02:17 PM
Hi

I have an array like this (it could be anything)

array = ["cat", "bird", "dog", "kittie", "cow"]

and i want to cut out the dog, how to do that if I DONT KNOW that it is nr2 in the array. I was figuring out the splice command but there you must know where the string is in the array.

Thanks

jimburton
02-09-2002, 07:09 PM
best way to do this is to loop through the array like this:


animals = new Array("cat", "bird", "dog", "kittie", "cow");
for (i=0;i<animals.length;i++) {
if (animals[i] == "dog") {
animals.splice(i,1);
}
}


:)