【发布时间】:2014-07-15 09:16:57
【问题描述】:
这是我的代码,我有两个数组,想把它们放在另一个数组中,命名为数据:
data=[];
atIndex=0;
//userInfo is name and last name of user:
userInfo=['Mohammad','Kermani'];
//userKnow is stuff what a user know:
userKnow=['php','javascript'];
data[atIndex]=userInfo;
data[atIndex]=userInfo;
data[atIndex]=userKnow;
//I want to send data with json,and decode it with php:
console.log(data);
但现在只有最后一个数据在数据中
可能是嵌套数组或两个痴呆数组
【问题讨论】:
-
为什么你只使用索引
0来添加你的值。以及为什么多次使用它data[atIndex]=userInfo;data[atIndex]=userInfo;。使用Array.push()向数组添加元素 -
您希望结果是什么样的?
-
也许您正在寻找
data.push()? -
@Barmar 我需要这样的东西:({Mohammad,Kermani},{php,javascript})
-
使用 'data.push()' 进行推送
标签: javascript arrays json