var arr = ["himanshu","shekhar","vinod","harry"];
for loop:
----------
for(let i = 0;i<arr.length;i++){
console.log(arr[i]);
}
For in loop :
------------
for(let i in arr){
console.log(i); //return index number
}
for of loop:
---------------
for(let i of arr){
console.log(i); //return element of that array
}
for-each loop:
---------------
arr.forEach(function(element,index,arr){
console.log(element,index,arr)
})
note: we can use break in for-each loop
for-each loop using fat arrow function :
-----------------------------------------
arr.forEach((element,index,arr) =>{
console.log(element,index,arr)
});
0 Comments