<!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>
const
Instead of var
: Prefer using const
or let
for declaring variables. 2. Array Functions: - forEach
Method: Use forEach
to loop through arrays more efficiently. - Template Literal: Utilize template literals for cleaner string concatenation. 3. Use Modern Syntax: - let
and const
: Use b-scoped declarations instead of var
. - Arrow Functions: Shorter syntax for function definitions. 4...const
Instead of var
: Prefer using const
or let
for declaring variables. 2. Array Functions: - forEach
Method: Use forEach
to loop through arrays more efficiently. - Template Literal: Utilize template literals for cleaner string concatenation. 3. Use Modern Syntax: - let
and const
: Use b-scoped declarations instead of var
. - Arrow Functions: Shorter syntax for function definitions. 4. Semantic HTML: - Ensure your HTML structure adheres to best practices such as using a proper doctype and semantic elements. Here's an updated version of your code with modern JavaScript features:
DOCTYPE html> [HEADING=1]JavaScript Arrays[/HEADING] The best way to loop through an array is using a standard for loop: