[英]Javascript Pass Array as a Parameter to a Function with Multiple Parameters
I am trying to pass a string variable and two arrays to a global function. 我试图将一个字符串变量和两个数组传递给全局函数。 Something like this: 像这样:
function send_times_to_device(stop_name, times, headsigns) {
// function code here
}
Later in code: 稍后的代码:
...
var stop_name = "temp";
var times = new Array(json.length);
var headsigns = new Array(json.length);
...
if(times.length < 6){
send_times_to_device(stop_name, times, headsigns);
}
...
How would I do this correctly in Javascript? 如何在Javascript中正确执行此操作?
Thanks in advance! 提前致谢!
EDIT: You guys were right, there was an error elsewhere in my code, this works! 编辑:你们是正确的,在我的代码的其他地方有一个错误,这有效!
new Array(n), creates an array with n undefined entries in it. new Array(n),创建一个包含n个未定义条目的数组。
If you want to create an array with an integer value as the first entry use : 如果要创建一个具有整数值的数组作为第一个条目,请使用:
function send_times_to_device(stop_name, times, headsigns) {
// function code here
console.log(stop_name);
console.log(times);
console.log(headsigns);
}
var stop_name = "temp";
var times = [json.length];
var headsigns = [json.length];
send_times_to_device(stop_name, times, headsigns);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.