Loops in ECMAScript

Create new Javascript file named index.js. This file contains code demo as below:

const names = ['Name 1', 'Name 2', 'name 3', 'Name 4'];

console.log('Name List');
for (const index in names) {
    console.log(index + ': ' + names[index]);
}

console.log('Name List');
for (const name of names) {
    console.log(name);
}




Use node index.js statement run code demo

Name List
0: Name 1
1: Name 2
2: name 3
3: Name 4

Name List
Name 1
Name 2
name 3
Name 4