Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将可变长度数组传递给函数节点JS_Javascript_Node.js_Variables - Fatal编程技术网

Javascript 将可变长度数组传递给函数节点JS

Javascript 将可变长度数组传递给函数节点JS,javascript,node.js,variables,Javascript,Node.js,Variables,有没有一种方法可以调用长度可变的加载项函数。我将用户输入带入一个变量 Uinput = [5,3,2]; 现在我想根据这些数字给我的插件打电话 addon.myaddon(5,3,2); 我还想把它扩展到n个输入,所以如果我的用户输入变量变为 Uinput = [5,3,2,6,...,n]; 然后插件将被称为 addon.myaddon(5,3,2,6,...,n); addon.myaddon(Uinput) // will not seperate the inputs by c

有没有一种方法可以调用长度可变的加载项函数。我将用户输入带入一个变量

Uinput = [5,3,2]; 
现在我想根据这些数字给我的插件打电话

addon.myaddon(5,3,2);
我还想把它扩展到n个输入,所以如果我的用户输入变量变为

Uinput = [5,3,2,6,...,n];
然后插件将被称为

addon.myaddon(5,3,2,6,...,n);

addon.myaddon(Uinput) // will not seperate the inputs by commas are they are in the array variable, it treats the whole array as the input
这似乎很简单,但给我带来了一些麻烦。有什么建议吗?

看看

这相当于调用:

addon.myaddon(Uinput[0], Uinput[1], Uinput[2], ... , Uinput[n]);
实际示例使用:


非常感谢。我会尽快接受。我知道我错过了一些简单的复制品
addon.myaddon(Uinput[0], Uinput[1], Uinput[2], ... , Uinput[n]);
// Basic example
Math.max(1,6,3,8,4,7,3); // returns 8

// Example with any amount of arguments in an array
var mySet = [1,6,3,8,4,7,3];
Math.max.apply(null, mySet); // returns 8