JavaScript iterate key & value from json?

This question already has an answer here:

  • How do I loop through or enumerate a JavaScript object? 29 answers

  • 使用Object.keys()获取键数组并使用forEach()遍历它们。

    var data = {
      "VERSION": "2006-10-27.a",
      "JOBNAME": "EXEC_",
      "JOBHOST": "Test",
      "LSFQUEUE": "45",
      "LSFLIMIT": "2006-10-27",
      "NEWUSER": "3",
      "NEWGROUP": "2",
      "NEWMODUS": "640"
    };
    
    Object.keys(data).forEach(function(key) {
      console.log('Key : ' + key + ', Value : ' + data[key])
    })

    你可以使用Object.keys

    var keys = Object.keys(yourObject);
    for(var i=0;i<keys.length;i++){
        var key = keys[i];
        console.log(key, yourObject[key]);
    }
    
    链接地址: http://www.djcxy.com/p/28820.html

    上一篇: HashMap对象在JavaScript中

    下一篇: JavaScript从json迭代键和值?