Answers for "javascript array methods foreach"

131

javascript foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
Posted by: Guest on April-27-2020
23

foreach jas

const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));
Posted by: Guest on January-10-2020
8

javascript foreach

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

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

what is foreach method in javascript

var arr = [1, 2, 3, 4, 5, 6];

//var sum = 0;
arr.forEach(function (value, index, array){  // Built in method
    //sum += value;
    console.log(value, index, array);
})

//console.log(sum);  // We can print sum of all Array element (if those are numbers)

// function forEach(arr, cb){  // How forEach() method works
//     for (var i = 0; i<arr.length; i++){
//         cb(arr[i], i, arr);
//     }
// }
// var sum = 0;
// forEach(arr, function (value, index, arr){
//     console.log(value, index, arr);
//     sum += value;
// })
// console.log(sum);
Posted by: Guest on December-28-2020

Code answers related to "javascript array methods foreach"

Code answers related to "Javascript"

Browse Popular Code Answers by Language