[英]console.log not showing js value
I am iterating through JSON data, but I am not able to get the value in console.log
.我正在遍历 JSON 数据,但无法获取console.log
的值。 Can you tell me how to fix it?你能告诉我如何解决吗? I am writing the correct syntax for my console.我正在为我的控制台编写正确的语法。 I'm providing my code below:我在下面提供我的代码:
http://jsfiddle.net/7Bn63/4/ http://jsfiddle.net/7Bn63/4/
function allProfile() {
for (var i = 0; i < allProfile.length; i++) {
console.log("i am here");
console.log(allProfile[i].Class of Service 1);
}
}
var allProfile = [{
Profile: 101,
'Class of Service 1': '90%'
}];
You'll have use bracket notation to access that property您必须使用括号表示法来访问该属性
allProfile[i]['Class of Service 1']
and your function has the same name as the object, so it's overwritten并且您的函数与对象具有相同的名称,因此它被覆盖
function iterator() {
for (var i = 0; i < allProfile.length; i++) {
console.log(allProfile[i]['Class of Service 1']);
}
}
var allProfile = [{
Profile: 101,
'Class of Service 1': '90%'
}];
iterator();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.