for(let i = 0; i < 5; i++) {
console.log(i);
}
/* output
0
1
2
3
4
*/
const myArray = ["Harry", "Ron", "Hermione", "Tom"];
for(let i = 0; i < myArray.length; i++) {
console.log(myArray[i]);
}
/* output
Harry
Ron
Hermione
Tom
*/
let myArray = ["Harry", "Ron", "Hermione", "Tom"];
for(const arrayItem of myArray) {
console.log(arrayItem)
}
/* output
Harry
Ron
Hermione
Tom
*/
let bulan = ["januari", "februari", "maret", "april", "mei"]
console.log("===for loop model lama===");
for(let i = 0; i < bulan.length; i++){
console.log(bulan[i]);
}
console.log(" ");
console.log("===for loop model baru===");
for(const namaBulan of bulan){
console.log(namaBulan);
}