In the first half of the year, during ExtJS, specific elements in the array need to be deleted directly due to some special circumstances of the project,
The input parameter may be a subscript or an array element.
So I am struggling with the following method, and I will check it later.
/**
* Method: Array. remove (dx)
* Function: delete array elements from the original array.
* Parameter: dx deletes the subscript of an element or array element (subscript by default)
* Return value: the elements of the deleted array.
*/
// Obtain the index of the specified Element in the array
Array. prototype. getIndexByValue = function (value ){
Var index =-1;
For (var I = 0; I <this. length; I ++ ){
If (this [I] = value ){
Index = I;
Break;
}
}
Return index;
}
// Refactor the array through traversal.
Array. prototype. remove = function (dx ){
Var me = this, removed = null;
If (dx> me. length-1 ){
Return false;
}
If (isNaN (dx )){
Removed = me. remove (me. getIndexByValue (dx ));
} Www.2cto.com
For (var I = 0, n = 0; I <me. length; I ++ ){
If (me [I]! = Me [dx]) {
Me [n ++] = me [I]
} Else {
Removed = me [I];
}
}
If (removed)
Me. length-= 1;
Return removed;
}