I would like to know how to loop multiple objects inside an array in vanilla JavaScript.
The below example doesn't work and I don't know why.
<!DOCTYPE html>
<html>
<body style="background-color: #d89797;">
<h2>JavaScript Arrays</h2>
<p>The best way to loop through an array is using a standard for loop:</p>
<p id="demo"></p>
<script>
var fruits, text, fLen, i;
fruits = [{
"customerID": "10",
"countInvoices": "42",
"name": "Xuseen"
},
{
"customerID": "100",
"countInvoices": "420",
"name": "khalid khalid"
}
];
fLen = fruits.length;
text = "<ul>";
for (i = 0; i < fLen; i++) {
text += "<li>" + fruits[i] + "</li>";
}
text += "</ul>";
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
Thanks.