I am trying to use innerHTML with arrays and it does not work, but if i use document.write my function works properly and I get the following: product 1 price 1 product 2 price 2 product 3 price 3 product 4 price 4 product 5 price 5 Any help will be appreciated. Following is the code:
var items = [
["product 1", "price 1"],
["product 2", "price 2"],
["product 3", "price 3"],
["product 4", "price 4"],
["product 5", "price 5"]
];
function testButton() {
var j = 0;
for (var i = 0; i < items.length; i++) {
for (var j = 0; j < 2; j++) {
document.getElementById("buttons").innerHTML = items[i][j] + "<br>";
/*document.write(items[i][j] + "<br>");*/
}
}
}
#buttons {
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
width: 100vw;
height: 100vh;
text-align: center;
text-transform: uppercase;
padding: 10px;
font-size: 2em;
border: solid;
}
<button id="buttons" onclick="testButton()">Next</button>