PDA

View Full Version : Removing ONE SPECIFIED element from array


Miroku_87
05-18-2010, 07:37 PM
Hi guys, how can I make a function which does this?
var array:Array = ["europe","america","asia","africa","oceania"]
array.remove("asia"); //array now is ["europe","america","africa","oceania"]

Thanx in advance =)

neilmmm
05-18-2010, 08:24 PM
var array:Array = ["europe", "america", "asia", "africa", "oceania"];
function remove(target) {
for (i=0; i<array.length; i++) {
if (target == array[i]) {
array.splice(i, 1);
trace(array);
}
}
}
remove("asia");

Miroku_87
05-18-2010, 08:28 PM
Thanx a lot =)

neilmmm
05-18-2010, 08:31 PM
welcome