我想创建一个多维数组并循环遍历它。我知道这是可能的,因为我已经读过它,但我仍然不明白为什么这不起作用......
var bundeslan = [
["city1"][19161],
["city2"][19162],
["city3"][19162]
];
console.log(bundeslan);
我想将每个城市与一个数字相关联,并使用该数字来标识一个 div。
我的想法是像这样循环数组......
//Start main loop
$.each(bundeslan, function( key, value ) {
//Inner loop
$.each(key, function(innerKey, innerValue){
alert(innerValue);
});
});
但是为什么我在 console.log(bundeslan)
中感觉像 [undefined][undefined][undefined]
等...?
最佳答案
存在语法错误。这样做。
var bundeslan = [
[["city1"],[19161]],
[["city2"],[19162]],
[["city3"],[19162]]
];
这会给你想要的结果
$.each(bundeslan, function( key, value ) {
//Inner loop
console.log(value[1][0]);
});
关于jquery - 为什么在 jquery (javascript) 中创建多维数组时出现未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33078071/