“metode javascript foreach ()” Kode Jawaban

JavaScript foreach

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

metode javascript foreach ()

// Create a Set
const letters = new Set(["a","b","c"]);

// List all Elements
let text = "";
letters.forEach (function(value) {
  text += value;
})
naly moslih

metode javascript foreach ()

// List all entries
let text = "";
fruits.forEach (function(value, key) {
  text += key + ' = ' + value;
})
naly moslih

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

Jawaban yang mirip dengan “metode javascript foreach ()”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya