// returns index of an item in array, -1 if it isn't in the array function inArray(array:Array, item:Object):Number { for (var i in array) { if (array[i] == item) { return Number(i); } } return -1; }
// tries to remove an item from array and returns whether it worked function arrayRemove(array:Array, item:Object):Boolean { var index:Number = inArray(array, item); if (index != -1) { array.splice(index, 1); } return index != -1; }
var names:Array = new Array("Bob", "Shirley", "Pete");trace(arrayRemove(array, "Bob")); // traces "true"trace(arrayRemove(array, "Bill")); // traces "false"