用传递的变量填充Javascript 2d数组

用传递的变量填充Javascript 2d数组,javascript,Javascript,我创建了一个50乘2的二维数组,并希望用传递的数组填充它。我知道数组是有效的,传递的变量也是有效的。但是我不能让传递的变量填充数组,它只是用纯文本填充。我的语法错了吗 for (i=0; i <50; i++){ basket[i]=new Array(2); } function addtobasket(itemname, itemvalue){ basket[itemcount][itemcount]='itemname itemvalue;' } for(i=0;i

我创建了一个50乘2的二维数组,并希望用传递的数组填充它。我知道数组是有效的,传递的变量也是有效的。但是我不能让传递的变量填充数组,它只是用纯文本填充。我的语法错了吗

for (i=0; i <50; i++){
basket[i]=new Array(2); 
}

function addtobasket(itemname, itemvalue){
    basket[itemcount][itemcount]='itemname itemvalue;'  
}

for(i=0;i
for(i=0;i
for(i=0;i
'itemname itemvalue'
将只使用'itemname itemvalue'填充数组

所以你需要写:

basket[itemcount][itemcount]=itemname+' '+itemvalue;

别忘了在字符串后面加分号。

'itemname itemvalue'
只会用'itemname itemvalue'填充数组

所以你需要写:

basket[itemcount][itemcount]=itemname+' '+itemvalue;

不要忘了在字符串后面加分号。

数据的预期格式是什么?纯文本。语法是:basket[itemcount][itemcount]=(itemname,itemvalue)嗯,你说它已经填充了纯文本,你想要纯文本,所以我想知道你的问题是什么。你想要数据的预期格式是什么?纯文本。语法是:basket[itemcount][itemcount]=(itemname,itemvalue)嗯,你说它已经充满了纯文本,你想要纯文本,所以我想知道你的问题是什么。