let items =['beef','cabbage','javascript'];// Defines a list of itemsfor(let item of items){// Defines for loop with a variable of 'item'console.log(item);// Prints the item that is found}
for(i in things){// If things is an array, i will usually contain the array keys *not advised*// If things is an object, i will contain the member names// Either way, access values using: things[i]}
var car ={"Tesla":"Model 3","Mercedes":"V-8 Model"};for(brandName in car){console.log(brandName);}//Tesla//Mercedesfor(brandName in car){console.log(car[brandName]);}//Model 3//V-8 Model
const user ={name:'Shirshak',age:25,subscibers:200,money:'lolno'}for(let x in user){console.log(user[x])//name,age,subscriber and money(only get key not value)}
//first typefor(let i; i< number; i++){//do stuff//you can breakbreak}//2nd typeconst colors =["red","green","blue","primary colors"]
colors.forEach((color)=>{//do stuff //But you can't breack out of the loop})//3rd type might not be considered as a loop
colors.map((color)=>{//do stuff//no bracking})
let list =["a","b","c"];// for infor(let i in list){// i is indexconsole.log(i);// "0", "1", "2",console.log(list[i]);// "a", "b", "c"}// for offor(let i of list){// i is valueconsole.log(i);// "a", "b", "c"}