Answers for "for() javascript loop"

220

javascript for loop

var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) { 
  console.log(colors[i]);
}
Posted by: Guest on June-17-2019
1

loop elements in javascript

var list = [{a:1,b:2}, {a:3,b:5}, {a:8,b:2}, {a:4,b:1}, {a:0,b:8}];

for (var i = list.length - 1, item; item = list[i]; i--) {
  console.log("Looping: index ", i, "item", item);
}

######### ES6 Update ################

for (let item of list) {
    console.log("Looping: index ", "Sorry!!!", "item" + item);
}
Posted by: Guest on October-22-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language