In this tutorial learn how works Array with foreach() loop in javaScript, List each item in the array example:
<!DOCTYPE html>
<html>
<body>
<p>List all array items, with keys and values:</p>
<p id="result"></p>
<script>
var fruits = ["Mango", "Banana", "Pineaple"];
fruits.forEach(foreachdemo);
function foreachdemo(item, index) {
document.getElementById("result").innerHTML += index + ":" + item + "<br>";
}
</script>
</body>
</html>
No comments:
Post a Comment