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

192
Visualizações
Changing the innerHTML by multiple elements with a loop

I'm trying to make a quiz app and i want to change the answers.innerHTML. I have an array in my questions object which contains the options.

options: ["Iran", "Ukraine", "Dagestan", "Turkmenistan"],

I've done it like this at the moment just to test if it works:

questions.answer1.innerHTML = questions.options[0];  
questions.answer2.innerHTML = questions.options[1];  
questions.answer3.innerHTML = questions.options[2];  
questions.answer4.innerHTML = questions.options[3];

But i want to do it somehow with a loop to make it DRY. I want to loop over the name of the declared element, like this:

for (const option of options) {  
    questions.answer[option].innerHTML = questions.options[option]  
}

Is there any way to loop over a declared variable's name?

about 4 years ago · Juan Pablo Isaza
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