I am facing a challenge with an array that was generated by another function and I don't want to make any modifications to it.
var d = [[1, 2, 3], [2, 3], [1, 3]];
My goal is to use the _.intersection
method on all arrays within the main array like this:
var c = _.intersection(d);
// expecting to get [3]
However, the _.intersection
method requires multiple array parameters as input, not an array of arrays.
I attempted to flatten the array using a similar approach mentioned in Merge/flatten an array of arrays in JavaScript?, but it flattened the entire array into one single array.
var merged = [].concat.apply([], d);
[1, 2, 3, 2, 3, 1, 3]; // This is not what I want
To provide more context, I have a nested array d
(which contains arrays and its length varies). My aim is to find the intersection of all arrays within the array d
.
Is there a way for me to dynamically call
based on the contents of array _.intersection([1, 2, 3], [2, 3], [1, 3], ...)
d
?