Parse Json array in JavaScript

This question already has an answer here:

  • How to loop through a plain JavaScript object with the objects as members? 17 answers

  • array.forEach(item => console.log(item.Name))
    
    array.forEach(item => console.log(item.Status.Id))
    

    你不能使用数组作为变量,所以替换为arr并尝试跟随,

    var arr =  [
        {"Name":"Test", "Status":{"Id":100, "Alias":"A"}},
        {"Name":"Test2", "Status":{"Id":101, "Alias":"B"}},
        {"Name":"Test3", "Status":{"Id":102, "Alias":"C"}}
        ];
    arr.forEach(function(item){
      console.log('Name: ' + item.Name);
      console.log('Status Id: ' + item.Status.Id);
      console.log('Status Alias: ' + item.Status.Alias);
    });
    链接地址: http://www.djcxy.com/p/52018.html

    上一篇: 从Javascript中的对象中删除空白属性

    下一篇: 使用JavaScript解析Json数组