I am doing an online course JavaScript. I am leraning right now the for loops and there are two types it is about: for (let i = 0; i < students.length; i++) for (let i in students) See the code. One is giving an output with student number 1-8 and the other gives an output like 01,11,21,31 aso. why?
"use strict"
const students= ["Melanie","Leni","Matilda","Niels","Anke","Juergen","Lilli","Hans"]
console.log("=========================================")
console.log("Variante 1\n")
for (let i = 0; i < students.length; i++) {
console.log(`Teilnehmer ${i+1} Name lautet: ${students[i]}`)
}
console.log("\n=========================================")
console.log("Variante 2\n")
for (let i in students) {
console.log(`Teilnehmer ${i+1} Name lautet: ${students[i]}`)
}
I expected the code to deliver the same output. If i remove the +1 it is the same.