Answers for "loop the array in javascript"

11

javascript iterate array

let array = ['Item 1', 'Item 2', 'Item 3'];

// Here's 4 different ways
for (let index = 0; index < array.length; index++) {
  console.log(array[index]);
}

for (let index in array) {
  console.log(array[index]);
}

for (let value of array) {
  console.log(value); // Will log each value
}

array.forEach((value, index) => {
  console.log(index); // Will log each index
  console.log(value); // Will log each value
});
Posted by: Guest on March-26-2020
48

js loop 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
13

loop through an array javascript

let array = ['Item 1', 'Item 2', 'Item 3'];

// Here's 4 different ways
for (let index = 0; index < array.length; index++) {
  console.log(array[index]);
}

for (let index in array) {
  console.log(array[index]);
}

for (let value of array) {
  console.log(value); // Will log value in array
}

array.forEach((value, index) => {
  console.log(index); // Will log each index
  console.log(value); // Will log each value
});
Posted by: Guest on March-25-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
0

javascript loop array

var data = {
  name: "root",
  contents: [
    {
      name: "A",
      contents: [
        {
          name: "fileA1",
          contents: ["Hello!"]
        }
      ]
    },
    {
      name: "B",
      contents: [
        {
          name: "dirB1",
          contents: [
            {
              name: "fileB1.1",
              contents: ["Hello!"]
            }
          ]
        }
      ]
    }
  ]
};
Posted by: Guest on May-11-2021
0

javascript loop array

Hi,

Une demande de connexion a été soumise pour votre compte $email à :
$site_name - $site_url

Connectez-vous à $site_name en visitant cette URL : 
$login_url

Si vous n'avez pas demandé l'URL de connexion, veuillez ignorer cet e-mail.

Salutations,
$site_name
Posted by: Guest on April-25-2021

Code answers related to "loop the array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language