【发布时间】:2015-09-13 01:28:45
【问题描述】:
我正在尝试遍历 JavaScript 数组并将单个对象值显示为警报。基本上,该数组包含 person 类型的对象
"person" : {
"id": String,
"name": String,
"address": String
}
而我的数组如下:
//This is where I get my array from the code behind. It's not empty. I checked
var obj = JSON.parse(val)
obj.forEach(function (entry) {
console.log(entry);
//This prints the entire array and its objects
});
我要的不是打印整个数组,我要打印:
obj.forEach(function (entry) {
console.log(entry[1].name);
console.log(entry[1].address);
//This prints the entire array and its objects
});
我应该对我的代码应用哪些更改?
【问题讨论】:
-
去掉那些 '[1]' ,因为 entry 已经是数组的一个元素了;)
标签: javascript asp.net arrays json