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

191
Views
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
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!