Search code examples
javascriptlodash

Compare 2 array and fetch unequal field


let arr1=[1,2,3]
let arr2=[1,2,3,4,5,6]

I want to compare 2 array and obtain the array list which is not in arr1

i.e output as arr3=[4,5,6]

Approaches using lodash/Javascript


Solution

  • Use diffrence method from lodash

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