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?