angularjs 刪除數組的值


全局變量定義:

 1 /**
 2  *刪除數組指定下標或指定對象
 3  */
 4 Array.prototype.remove=function(obj){
 5     for(var i =0;i <this.length;i++){
 6         var temp = this[i];
 7         if(!isNaN(obj)){
 8             temp=i;
 9         }
10         if(temp == obj){
11             for(var j = i;j <this.length;j++){
12                 this[j]=this[j+1];
13             }
14             this.length = this.length-1;
15         }
16     }
17 }
View Code

刪除方法:

 1 $scope.removeByValue = function(arr, val) {
 2     for(var i=0; i<arr.length; i++) {
 3         if(arr[i] === val) {
 4             arr.splice(i, 1);
 5             break;
 6         }
 7     }
 8 };
 9 $scope.unSuspectAll = function(data) {
10     var item =  data.suspectList;
11     for(var i=0;i<item.length;i++){
12   
13 $scope.removeByValue($scope.SuspectFrom.ids1,item[i].suspectId);
14     }
15 };
View Code

 

轉載於:https://www.cnblogs.com/miny-simp/p/7776690.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM