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

前端 未结 12 2131
广开言路
广开言路 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:40

    Your code with _lodash is working fine.

    As you can say in this fiddle:

    this code:

    var arrayOfArrays = [[4234, 2323, 43], [1323, 43, 1313], [23, 34, 43]];
    var a = _.intersection.apply(_, arrayOfArrays);
    console.log(a);
    console.log(a.length);
    

    Will have output:

    [42]
    1
    

    Maybe you see

    equals: function

    because you are using kind of debugger.

    Try to just print the array with console.log, you will get only 42.

提交回复
热议问题