remove common elements of two arrays in jquery

前端 未结 4 1419
粉色の甜心
粉色の甜心 2021-01-18 03:54

I want to remove common elements of two arrays in jquery. I have two arrays:

A = [0,1,2,3]
B = [2,3]

and result should be [0, 1]

4条回答
  •  后悔当初
    2021-01-18 04:24

    Use the Set type from ES6. Then the spread operator to build an array from the Set. A Set type can only hold unique items.

    const A = [1, 2, 3, 4];
    const B = [2, 4];
    const C = [...new Set(A,B)];
    
    console.log(C);
    
    
    
    (4) [1, 2, 3, 4]
    

提交回复
热议问题