如何将数组的数组作为一系列变量传递?
How to pass array of arrays as a series of variables?
我有一个数组:
[
[1,2],
[2,3],
[4,3]
]
我想将它们作为一系列变量传递给下划线函数。
_.intersection([1,2],[2,3],[4,3])
如何做到这一点?
您可以使用apply
_.intersection.apply(_, myArr);
- apply 方法的第一个参数是
this
要在被调用方法上设置的上下文。
- 第二个参数是一个数组,其元素将作为单独的参数传递给被调用的方法。
The apply() method calls a function with a given this value and arguments provided as an array (or an array-like object).
我有一个数组:
[
[1,2],
[2,3],
[4,3]
]
我想将它们作为一系列变量传递给下划线函数。
_.intersection([1,2],[2,3],[4,3])
如何做到这一点?
您可以使用apply
_.intersection.apply(_, myArr);
- apply 方法的第一个参数是
this
要在被调用方法上设置的上下文。 - 第二个参数是一个数组,其元素将作为单独的参数传递给被调用的方法。
The apply() method calls a function with a given this value and arguments provided as an array (or an array-like object).