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

73
Views
loop through object array with entires method

I have one array object
I want loop that with entires() method and display all score
My code is:

const obj = [
    { name: "a", score: 5 },
    { name: "b",score: 8 },
    { name: "c",  score: 10 },
    { name: "d",score: 19 }
];

const a = obj.entries();
Array.from(a).forEach((element) => {
    document.getElementById("p2").innerHTML += element.score;
});

<p id="p2"></p>

but got undefinedundefinedundefinedundefined what is solution?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can try this code, it not recommended to use .innerHTML to edit element html, it's better to append an element inside :

const obj = [
    { name: "a", score: 5 },
    { name: "b",score: 8 },
    { name: "c",  score: 10 },
    { name: "d",score: 19 }
];

const container = document.querySelector('#p2')

for(let el of obj) {
    let p = document.createElement('p');
    p.innerText = `${el.name} => ${el.score}`;
    container.appendChild(p);
}

I changed the output a little bit to make it clearer for bebug, of course you can put what ever you want inside the .innerText ;)

about 4 years ago · Santiago Trujillo 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!