-3

I have an object which helds an array of owners objects.

 carData.Porsche[0].OwnerName;
 carData.Porsche[1].OwnerName;
 carData.Ferrari[0].OwnerName;
 carData.Ferrari[1].OwnerName;
 carData.Ferrari[2].OwnerName;

I would like to iterate through this data structure so I will print:

Porsche: OwnerName,  Porsche: OwnerName, Ferrari: OwnerName etc..

but I have no clue how ( I'm new to Javascript). Would appreciate some tips.

Maciej Czarnota
  • 559
  • 2
  • 8
  • 16

1 Answers1

-1

Use a for loop to iterate the object

for (let in carData) {

  let car = carData[i];
  for (let j in car) {

    console.log(car[j].OwnerName);

  }

}
Ivan
  • 34,531
  • 8
  • 55
  • 100