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

233
Views
Generating List Items from an Array with Javascript

I am trying to generate a list of names from an Array with this piece of script

const names = ["John", "Hanna", "Luis", "Halley", "Maive"]
const list = document.getElementById('my_list')

names.forEach((name) => {
  let li = document.createElement("li")
  li.innerHTML = name
  list.appendChild(li)
})

and this html

<ul id="my_list"></ul>

but its not working. What am I doing wrong?

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

0

You're code works fine I suggest you a slightly different implementation with just one DOM update

const names = ["John", "Hanna", "Luis", "Halley", "Maive"]

window.onload = () => {
  const list = document.getElementById('my_list')
  list.innerHTML = names.map(name => `<li>${name}</li>`).join('')
}
<ul id="my_list"></ul>

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!