I know this question, the simplest code for intersecting an array , but all solutions assume that the number of arrays is two, which cannot be sure in my case.
I have divs on a data page that contain arrays. I want to find values ββcommon to all arrays. I don't know how many div / arrays I will have in advance. What is the best way to calculate the values ββcommon to all arrays?
var array1 = ["Lorem", "ipsum", "dolor"]; var array2 = ["Lorem", "ipsum", "quick", "brown", "foo"]; var array3 = ["Jumps", "Over", "Lazy", "Lorem"]; var array4 = [1337, 420, 666, "Lorem"];
I found another solution elsewhere using Underscore.js.
var arrayOfArrays = [[4234, 2323, 43], [1323, 43, 1313], [23, 34, 43]]; _.intersection.apply(_, arrayOfArrays)
I tested this with simple dummy data at the end and it seemed to work. But for some reason, some of the arrays I create that contain simple strings also automatically include the added value, "equals: function":
["Dummy1", "Dummy2", "Dummy3", equals: function]
And whenever I use the intersection method Underscore.js, in an array of arrays I always get [equals: function] in dev tools, and not if "Dummy3" is common to all arrays - ["Dummy3"].
So TL; DR is there another solution to traverse the array that suits my case? And can anyone explain what [equals: function] means here? When I expand an element in dev tools, it creates an empty array and a list of available methods on arrays (pop, push, shift, etc.), But all these methods disappear, and the equals: function is highlighted.