Answers for "for each for loop javascript"

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
35

for each js

const fruits = ['mango', 'papaya', 'pineapple', 'apple'];

// Iterate over fruits below

// Normal way
fruits.forEach(function(fruit){
  console.log('I want to eat a ' + fruit)
});
Posted by: Guest on March-29-2020
14

for each javascript

let numbers = ['one', 'two', 'three', 'four'];

numbers.forEach((num) => {
  console.log(num);
});  // one   //two //three // four
Posted by: Guest on July-16-2020
3

for in loop javascript

let array = [1,2,3,4,5,6,7,8,9,10]; 
// our array that we will use the for loop on
for (let i = 0; i < array.length; i++) { 
  // this loop will console log the element at array[i] starting at 0
  // and will continue looping for i < array.length 
  console.log(array[i]);
  // after each loop i will increase by 1
}

// this will console log
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
Posted by: Guest on October-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language