数组比较并取出不同值

  • Post author:
  • Post category:其他


数组比较取值根据需求分为取单个值和取多个值


```javascript
let c = [];        
let tmp = arr1.concat(arr2);      
 let o = {};        
 for (let s = 0; s < tmp.length; s++) {       
   (tmp[s] in o) ? o[tmp[s]]++ : o[tmp[s]] = 1;      
 }       
 for (let x in o) {
   if (o[x] == 1) {
     c = x;
   }
 } 


```javascript
  arrayRepeat(array1, array2) {
     let c = [...array1, ...array2],
      d = new Set(c),
      e = Array.from(d),
      f = [...e.filter(_=>!array1.includes(_)),...e.filter(_=>!array2.includes(_))]
      return f
   },



版权声明:本文为ghyxx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。