I'm looping through an array. Each iteration, I set the value of a variable to the current index in the array and append it to a div in my HTML. However, only the last index is being appended to the div.
Here's my code:
for (var i = 0; i < pronouns.length; i++) {
var para = document.createElement("P");
para.innerHTML = pronouns[i];
para.style = "display: inline-block";
alert(pronouns[i])
document.getElementById("main").appendChild(para);
document.getElementById("main").appendChild(input);
document.getElementById("main").appendChild(br);
}
pronouns
is equal to: ['I','Me','You']
.
Can anyone help?