Remover item específico de uma matriz de javascript que corresponde a uma string passada
Aqui há maneira rápida de ampliar o objeto de matriz nativa Javascript, só para fazer isso ...
Array.prototype. removeItem =function(str) {
for(i=0; i<this.length ; i++){
if(escape(this[i]).match(escape(str.trim()))){
this.splice(i, 1); break;
}
}
return this;
}
Então, agora você pode fazer algo assim ...
var animals= new Array("dog","lion","cat","tiger","elephant");
animals. removeItem ('tiger');Agora a matriz animais conterá "cão", "leão", "gato", "elefante";
PS: E aqui está o protótipo de Cordas da guarnição também ...
String.prototype.trim=function(str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
Aproveite ....










































