codice:
Array.prototype.deleteItem = function(item)
{
for(var i = 0; i < this.length; i++){
if(this[i] == item){
this.splice(i, 1);
return true;
}
}
return false;
};
Array.prototype.countItem = function(item)
{
var counter = 0;
for(var i = 0; i < this.length; i++){
if(this[i] == item)counter++;
}
return counter;
};
arrayNumero1 = ["uno", "due", "tre", "quattro", "cinque", "sei"];
trace("array originale: " + arrayNumero1);
arrayNumero1.deleteItem("due");
trace("array modificato: " + arrayNumero1);
arrayNumero2 = ["uno", "due", "due", "due", "uno", "sei"];
trace("l'elemento 'due' è presente " + arrayNumero2.countItem("due") + " volte");