JavaScript
Iterating through an array

by Benny Neugebauer

const array = ['A', 'B', 'C'];

for (let i = 0; i < array.length; i++) {
  const item = array[i];
  console.log('Item', item);
}

const array = ['A', 'B', 'C'];

for (const item of array) {
  console.log('Item', item);
}

http://jsben.ch/#/3cAu8

Rodrigo Espinosa

i'd recommend for loop with cached length instead (as rodrigo sent earlier):

for (let i = 0, len = array.length; i < len; i++) {

Aleksandr Strutynskyy

Sign in to comment!