2008 Primeiro de setembro de 2008

Eliminar elemento específico dunha matriz de javascript que corresponde a unha cadea pasada

Aquí hai maneira rápida de ampliar o obxecto de matriz nativa Javascript, só para facer iso ...

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ón, agora pode facer algo así ...

var animals= new Array("dog","lion","cat","tiger","elephant");
animals. removeItem ('tiger');

Agora a matriz animais conterá "can", "león", "gato", "elefante";

PS: E aquí está o prototipo de Cordas da guarnición tamén ...

String.prototype.trim=function(str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


Aproveitar ....


NDK casa | Expresando IT | Palate expresando | Penmenship expresando | AWE expresando | expresar o meu