AlishS
New Member
- Joined
- Oct 27, 2022
- Messages
- 9
- Thread Author
- #1
I learn javascript from an online resource. I got to this example. Is there any possibility how to write this code "better"? Is it not antiquated?
Code:
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<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 = ["Banana", "Orange", "Apple", "Mango"];
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>