const arr1 = [2, 1, 5, 6];
const arr2 = [2, 3, 10, 1];
//GET VALUES FROM arr1 that does not exist in arr2
const diff_arr = _.difference(arr1, arr2);
Live Demo :
In the code snippet, we are matching arr1 with arr2 and getting all values from arr1 in an array which does not exist in arr2. For this we are using lodash method _.difference. The syntax is for this is as below:
_.difference(Array, [Values to Match])
In the first paramter as an array we are passing our array whose values needs to be checked with second parameter array.
0 Comments