let colors = ['Red', 'Green', 'Blue'];
for (const [index, color] of colors.entries()) {
console.log(`${color} is at index ${index}`);
}Code language: JavaScript (javascript)
const array = ['a', 'b', 'c', 'd'];
for (const item of array) {
console.log(item)
}
// Result: a, b, c, d
const string = 'Ire Aderinokun';
for (const character of string) {
console.log(character)
}
// Result: I, r, e, , A, d, e, r, i, n, o, k, u, n
// for ... of ...
for (let char of "Hello") {
console.log(char);
}
// console result:
H
e
l
l
o
for (element of iterable) {
// body of for...of
}