for loop
console.log("for loop");
for(let i=0;i<10;i++)
{
console.log(i);
}
while loop
let i=0;
while(i<10)
{
console.log(i);
i++;
}
do-while loop
let i=0;
do
{
console.log(i);
i++;
}while(i<10)
forEach Loop
(used for iterate every value , it is a type of syntactic sugar , to write in a better way)
let arr2=[10,20,30,40];
arr2.forEach(function(element){
console.log(element);
})
forIn loop
(it is only used to iterate or display content present inside the object)
for(let key in obj)
{
// console.log(key);
// console.log(obj[key]);
console.log(The ${key} of the person is ${obj[key]}
);
}
Top comments (0)