I have a function that iterates through a 2d Array, every Array has a song and an interpreter and the function is supposed to run a loop and list every song with it's interpreter. The problem is that it only lists the last song and interpreter, what am I missing so it lists all of them?:
HTML:
<ul id="2d"> </ul>
JS
var twoDArray = [
["I did it my way", "Frank Sinatra"],
["Respect", "Areta Franklin"],
["Imagine", "John Lennon"]
];
function iterative( songs ) {
for ( var i = 0; i < songs.length; i += 1) {
document.getElementById("2d").innerHTML = "<li>" + songs[i][0] + " by " + songs[i][1] + "</li>";
}
}
iterative(twoDArray);
+=instead of=.