Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda