During ExtJS in the first half of the year, special elements in the array need to be directly deleted due to some special circumstances of the project, and the input parameters may be subscripts or array elements. So I am struggling with the following method, and I will check it later. /*** Method: Array. remove (dx) * power... syntaxHighlighter. all (); During ExtJS in the first half of the year, 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;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.