如何创建多维数组??
到目前为止我试过了:
var post_data = [];
var id = 1;
post_data[id] = [];
post_data[id]['name'] = 'abc';
post_data[id]['date'] = '01-03-2014';
post_data[id]['country'] = 'India';
console.log(post_data);
上面的代码没有给我key
。怎么了?
我想要这样的输出:
[1]=> array
(
"name": "abc",
"date": "01-03-2014",
"country": "India",
)
如何得到上面的输出???
最佳答案
为了得到想要的结果你可以改变
var post_data = [];
到
var post_data = {};
和
post_data[id] = {};
关于Javascript多维数组不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24994066/