How can I get the key value in a JSON object?

前端 未结 6 1726
北恋
北恋 2020-12-24 13:30

How do I get the key value in a JSON object and the length of the object using JavaScript?

For example:

[
  {
    "amount": " 12185"         


        
6条回答
  •  余生分开走
    2020-12-24 14:25

    JSON content is basically represented as an associative array in JavaScript. You just need to loop over them to either read the key or the value:

        var JSON_Obj = { "one":1, "two":2, "three":3, "four":4, "five":5 };
    
        // Read key
        for (var key in JSON_Obj) {
           console.log(key);
           console.log(JSON_Obj[key]);
       }
    

提交回复
热议问题