how to create array in javascript loop code example
Example 1: looping in javascript
<html>
<body>
<script type = "text/javascript">
<!--
var count;
document.write("Starting Loop" + "<br />");
for(count = 0; count < 10; count++) {
document.write("Current Count : " + count );
document.write("<br />");
}
document.write("Loop stopped!");
</script>
<p>Set the variable to different value and then try...</p>
</body>
</html>
Example 2: javascript loop through array
Array.prototype.myEach = function(callback) {
for (let i = 0 ; i < this.length ; i ++) {
callback(this[i]);
}
}
let array = ['Item 1', 'Item 2', 'Item 3', 'Item 4'];
array.myEach(function (element) {
console.log(element);
});