JavaScript
Loop shorthand

by Benny Neugebauer

const animals = ['ape', 'bear', 'zebra'];

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

const animals = ['ape', 'bear', 'zebra'];

for (let i in animals) {
  console.log(animals[i]);
}

What I like even more is:


const animals = ['ape', 'bear', 'zebra'];

animals.forEach(animal => console.log(animal));

Benny Neugebauer

Sign in to comment!