For loop through Array only shows last value

Change your for loop:

for (i = 0; i <= (n-1); i++) {
    var list = names[i];
    var myList = document.getElementById("list");
    myList.innerHTML += "<li class="list-group-item" id='listItem'>"+ list + "</li>" + "<br />";
}

Use += instead of =. Other than that, your code looks fine.

Leave a Comment