删除与另一个JSON javascript angularjs-JSON匹配的JSON

delete JSON which match to another JSON javascript angularjs json

本文关键字:JSON angularjs-JSON javascript 另一个 删除      更新时间:2023-09-26

JSON A['711','722','733','744']

JSON B[{pid:711,名称:"hello"},{pid:733,名称"world"}

试着删除与JSON A匹配的数组B。就像JSON B 711、733、744与JSON A的数组匹配一样,我想删除它们。

我尝试了以下函数,但不起作用,因为它总是有一个或两个字符串是miss-delete。

        angular.forEach(B, function(value, index){
              if(A.indexOf(value.pid) > -1){
             B.splice(index , 1);
        }
        });

循环通过数组A,然后使用filter函数过滤数组B并使用迭代器函数,只返回键"pid"不匹配的函数。

for(var c of A){
  B = B.filter(function(n){
    return n.pid !== parseInt(c)
  });
}

希望这对有帮助