How to calculate intersection of multiple arrays in JavaScript? And what does [equals: function] mean?

前端 未结 12 2149
广开言路
广开言路 2020-11-29 06:13

I am aware of this question, simplest code for array intersection but all the solutions presume the number of arrays is two, which cannot be certain in my case.

I ha

12条回答
  •  甜味超标
    2020-11-29 06:27

    For anyone confused by this in the future,

    _.intersection.apply(_, arrayOfArrays)
    

    Is in fact the most elegant way to do this. But:

    var arrayOfArrays = [[43, 34343, 23232], [43, 314159, 343], [43, 243]];
    arrayOfArrays = _.intersection.apply(_, arrayOfArrays);
    

    Will not work! Must do

    var differentVariableName = _.intersection.apply(_,arrayOfArrays);
    

提交回复
热议问题