const arr1 = [10, 20, 30];
const arr2 = [5, 20, 40, 30];
const result1 = _.intersection(arr1, arr2);
// => [20,30]
const arr3 = [20];
const result2 = _.intersection(arr1, arr2, arr3);
// => [20]
In the first example of code snippet, we have defined two arrays arr1 and arr2 and we are getting common values array or intersection array of them. While in the second example we are getting the intersection of three arrays.
_.intersection(Array1, Array2, ...)
You can pass as many arrays as you want to get the common values between them.
Example Demo
0 Comments