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

138
Views
Display the elements of the array one by one in a column js

I have an application where the user selects the words he will save. I write all these words into an array. I need to display each element of this array in a column so that when hovering over you could see the information (or by clicking) I tried to iterate over each element of the array using for and foreach but only the last element was displayed How can I arrange array elements in a column?

Array:

let a = ["First word","Second word","Third word"]

An example of what I need:

  • First word
  • Second word
  • Third word

Need to display it on the page through textContent or innerHTML or something like that.

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

0

What you can do is initializing a list and the adding dynamically all items to that list.

const words = ["First word","Second word","Third word"]

const list = document.getElementById('myList')

words.forEach(word => {
  const item = document.createElement('li')
  item.textContent = word // or item.innerHTML
  list.appendChild(item)
})
<ul id="myList"></ul>

about 4 years ago · Juan Pablo Isaza Report

0

Solution using for in:

let a = ["First word","Second word","Third word"],
  $list = document.querySelector('#list')

for(let i in a) {
  $list.insertAdjacentHTML('beforeend', `<li>${a[i]}</li>`)
}
<ol id="list">List of items
</ol>

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!