【问题标题】:console.log not showing js valueconsole.log 不显示 js 值
【发布时间】:2014-03-24 19:56:03
【问题描述】:

我正在遍历 JSON 数据,但无法获得 console.log 中的值。 你能告诉我如何解决吗? 我正在为我的控制台编写正确的语法。 我在下面提供我的代码:

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%'
        
}];

【问题讨论】:

  • allProfile[i].["Class of Service 1"] ?

标签: javascript jquery json jquery-ui


【解决方案1】:

您将使用括号表示法来访问该属性

allProfile[i]['Class of Service 1']

你的函数和对象同名,所以它被覆盖了

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();

FIDDLE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2021-11-30
    相关资源
    最近更新 更多