2015-10-23 226 views
0

我想将字符串变量和两个数组传递给全局函数。事情是这样的:JavaScript将数组作为参数传递给具有多个参数的函数

function send_times_to_device(stop_name, times, headsigns) { 
    // function code here 
} 

在后面的代码:

... 
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); 
} 
... 

我怎么会在Javascript中正确地做到这一点?

在此先感谢!

编辑: 你们是对的,我的代码在其他地方出现错误,这个工程!

+1

有错误吗? – MinusFour

+1

我没有看到问题 –

+0

,看起来技术上是正确的 – Jesse

回答

1

new Array(n),创建一个数组,其中包含n个未定义的条目。

如果你想用一个整数值作为第一个条目使用创建磁盘阵列:

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); 
相关问题