Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

405
Views
How to output everything from the object to the markup?

I have an array which contains objects. How to output everything from the object to the markup? I think I stuck in this part of code div_child.innerHTML On output I got this cars[object Object] eleven times.

Should be like this:

img car: 'Audi' model: 'A6' age: 2014 price: 20900

let cars = [];

cars[0] = {
  img: 'assets/img/img-1.webp',
  car: 'Audi',
  model: 'A6',
  age: 2014,
  price: 20900
}
// and 9 another objects of cars


let div = document.createElement('div');
div.className = 'cars-list';
for (let key in cars) {
  let div_child = document.createElement('div');
  div_child.className = 'cars-list__item';
  div_child.innerHTML = `${cars}` + `${cars[key]}`; // As I understood this is the root of problem
  div.append(div_child);
}
document.body.append(div);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Why is using "for...in" for array iteration a bad idea?

I would use a map:

let cars = [{
  img: 'assets/img/img-1.webp',
  car: 'Audi',
  model: 'A4',
  age: 2014,
  price: 20900
},{
  img: 'assets/img/img-2.webp',
  car: 'Audi',
  model: 'A5',
  age: 2014,
  price: 20900
},{
  img: 'assets/img/img-3.webp',
  car: 'Audi',
  model: 'A6',
  age: 2014,
  price: 20900
},
]
// and 9 another objects of cars


let div = document.createElement('div');
div.className = 'cars-list';
div.innerHTML = cars.map(car => `<div class="cars-list__item">${car.car}: ${car.model}</div>`).join("")
document.body.append(div)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!