代码之家  ›  专栏  ›  技术社区  ›  gautham shetty

比较2数组并获取不相等字段

  •  -2
  • gautham shetty  · 技术社区  · 8 年前
    let arr1=[1,2,3]
    let arr2=[1,2,3,4,5,6]
    

    我想比较2个数组并获得不在中的数组列表 arr1

    i、 e输出组件 arr3=[4,5,6]

    使用lodash/Javascript的方法

    2 回复  |  直到 8 年前
        1
  •  1
  •   CertainPerformance    8 年前

    const arr1=[1,2,3];
    const arr2=[1,2,3,4,5,6]
    const intersection = arr2.filter(elm => !arr1.includes(elm));
    console.log(intersection);
        2
  •  0
  •   Pramod Patil    8 年前

    使用lodash的差分法

     _.difference([1,2,3,4,5,6], [1,2,3]);