Answers for "for over array javascript"

48

javascript code to loop through array

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

javascript loop through array

const myArray = ['foo', 'bar'];

myArray.forEach(x => console.log(x));

//or

for(let i = 0; i < myArray.length; i++) {
  console.log(myArray[i]);
}
Posted by: Guest on November-16-2020
0

loop over an array

let fruits = ['Apple', 'Banana'];

fruits.forEach(function(item, index, array) {
  console.log(item, index);
});
// Apple 0
// Banana 1
Posted by: Guest on November-22-2020
0

loop over an array

fruits.forEach(function(item, index, array) {
  console.log(item, index)
})
// Apple 0
// Banana 1
Posted by: Guest on July-02-2021

Code answers related to "for over array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language