Answers for "js loop function"

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
14

javascript loop through array

var colors = ["red","blue","green"];
colors.forEach(function(color) {
  console.log(color);
});
Posted by: Guest on March-06-2020
8

for loop javascript

var listItem = [
        {name: 'myName1', gender: 'male'},
        {name: 'myName2', gender: 'female'},
        {name: 'myName3', gender: 'male'},
        {name: 'myName4', gender: 'female'},
      ]

    for (const iterator of listItem) {
        console.log(iterator.name+ ' and '+ iterator.gender);
    }
Posted by: Guest on May-09-2020
2

javascript for loop[

for(i=0;i<=5;i++){
  console.log(i);}
Posted by: Guest on June-12-2020
0

for loop js

let arr = [];
for(let i = 0; i <= 10; i++){
arr[i] = Math.round(Math.random() * 10);
}
•	Result: [3, 1, 1, 2, 3, 9, 5, 6, 6, 8, 5] 
•	                        Or
let arr = [];
for(let i = 0; i <= 10; i++){
arr[i] = Math.trunc(Math.random() * 10);
} 
Result[7, 6, 0, 2, 4, 8, 7, 5, 5, 6, 5]
Posted by: Guest on August-07-2020
-1

for loop in js

for (let counter = 1; counter < 3; counter++) {

    // console.log(counter,'\n');       
}
Posted by: Guest on April-20-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language