[Solved] How to read nested json object? [duplicate]


Simply do it by myObj.cars.car1 , myObj.cars.car2 and , myObj.cars.car3 to get directly or loop as below example

var myObj = {
  "name": "John",
  "age": 30,
  "cars": {
    "car1": "Ford",
    "car2": "BMW",
    "car3": "Fiat"
  }
};

for (let i in myObj) {
  if (typeof myObj[i] == 'object') {
    for (let j in myObj[i]) {
      console.log(j, myObj[i][j]);
    }
  } else {
    console.log(i, myObj[i]);
  }
}

solved How to read nested json object? [duplicate]