I have an array like the following which is computed from another function I don't want to modify.
var d = [[1, 2, 3], [2, 3], [1, 3]];
I want to use _.intersection
with all the arrays within the above array like this:
var c = _.intersection(d);
// should return [3]
but _.intersection
takes multiple array parameters as input, not an array of arrays.
I have tried to flatten an array using something similar to Merge/flatten an array of arrays in JavaScript? but it convert the whole array into a single array.
var merged = [].concat.apply([], d);
[1, 2, 3, 2, 3, 1, 3]; // I don't want this
Let me explain this in detail. I have a nested array d
(which contains arrays and length is dynamic). Now I want to find the intersection of all arrays that are within array d
.
How can I call _.intersection([1, 2, 3], [2, 3], [1, 3], ...)
but dynamically with d
?