How to get the difference of two string arrays?

前端 未结 3 1101
猫巷女王i
猫巷女王i 2021-01-15 05:51

I want to get the exact difference between two string arrays.

const array1 = [\'T\',\'E\',\'A\',\'P\',\'A\',\'P\',\'E\',\'R\'];
const array2 = [\'T\',\'A\',\         


        
3条回答
  •  甜味超标
    2021-01-15 06:29

    I think filter is not correct apparoch here. Because there are some elements repeadted. Use a simple for-loop. And remove the elements when you add it to result.

    const array1 = ['T','E','A','P','A','P','E','R'];
    const array2 = ['T','A','P'];
    const copy = [...array2];
    
    let res = [];
    for(let i = 0;i

提交回复
热议问题