美文网首页
获取2个数组中不同的元素

获取2个数组中不同的元素

作者: Amy_yqh | 来源:发表于2019-03-14 17:51 被阅读0次

    方法一

    function (oldVal,newVal){
      var removeItemFieldName = '';
              for(let i in oldVal){
                var stra = oldVal[i];
                var count = 0;
                for(let j in newVal){
                  var strb = newVal[j];
                  if(stra == strb){
                    count ++;
                  }
                }
                if(count=== 0){ 
                  removeItemFieldName=stra;
                }
              }
    reture removeItemFieldName
    }
    

    方法二:

       getDiff(arr1, arr2) {
            return arr1.filter(key => !arr2.includes(key))
          },
    

    相关文章

      网友评论

          本文标题:获取2个数组中不同的元素

          本文链接:https://www.haomeiwen.com/subject/edvcmqtx.html