OneBite.Dev - Coding blog in a bite size

loop array in Javascript

Code snippet on how to loop array in Javascript

  for (i=0; i<arr.length; i++) {
    console.log(arr[i]);
  }

This code loops through an array called “arr”. The loop starts with variable “i” set to 0, which is the first index of the array. Then it checks to see if the value of “i” is less than the array’s length. If it is, the code inside the loop is executed. In this case, it prints out the value at the index “i” in the array. After that, the variable “i” is incremented by 1. This process is repeated until the value of “i” is no longer less than the array’s length, at which point the loop ends.

javascript