“Foreach JS” Kode Jawaban

JavaScript foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
connect.sonveer

JavaScript foreach

var colors = ['red', 'blue', 'green'];

colors.forEach(function(color) {
  console.log(color);
});
Grepper

Indeks Foreach JavaScript

users.forEach((user, index)=>{
	console.log(index); // Prints the index at which the loop is currently at
});
Concerned Chipmunk

Foreach JavaScript

var items = ["item1", "item2", "item3"]
var copie = [];

items.forEach(function(item){
  copie.push(item);
});
Docteur SEO

Foreach JS

angular.forEach(obj1.results, function(result1) {
    angular.forEach(obj2.results, function(result2) {
        if (result1.Value === result2.Value) {
            //do something
        }
    });
});

//exact same with a for loop
for (var i = 0; i < obj1.results.length; i++) {
    for (var j = 0; j < obj2.results.length; j++) {
        if (obj1.results[i].Value === obj2.results[j].Value) {
            //do something
        }
    }
}
Defiant Dragonfly

Foreach JS

list = [0, 1, 2, 3,4]
for (let obj of list) {
    console.log(obj)
}
 Run code snippetHide results
Defiant Dragonfly

Jawaban yang mirip dengan “Foreach JS”

Pertanyaan yang mirip dengan “Foreach JS”

Lebih banyak jawaban terkait untuk “Foreach JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya