You wouldn't use forEach at all any more in ES6. You'd use a for of loop:

for (let div of document.querySelectorAll('div'))
    div.style.color = 'green';

Apart from that, you can use Array.from to cast an iterable object to an array and then invoke .forEach on that; but in fact with the upcoming DOM spec this is unnecessary where querySelectorAll will return an Elements collection that does inherit from Array in the ES6 way - so you can call the .forEach method directly on it!

Answer from Bergi on Stack Overflow
🌐
Jonathan Dempsey
jonathandempsey.dev › home › journal › javascript › javascript es6: the foreach() helper
JavaScript ES6: The forEach() Helper - Jonathan Dempsey
May 17, 2020 - forEach() is an ES6 helper that is used to call a function once on each item in an array and is arguably the most useful ES6 helper. Let's dig into how it works.
Discussions

Alternative for [].forEach.call(...) in ECMA6Script
Apart from that, you can use Array.from to cast an iterable object to an array and then invoke .forEach on that; but in fact with the upcoming DOM spec this is unnecessary where querySelectorAll will return an Elements collection that does inherit from Array in the ES6 way - so you can call ... More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Using find() inside forEach loop in javascript/es6 - Stack Overflow
But you are using ES6... ... You should define "better". What is the problem with this code? ... It's probably a good idea to create a hash from id to item for array2 and use that to get the new names. const idsToArray2 = array2.reduce( (acc, current) => { acc[current.id]=current; return acc }, {}) array1.forEach... More on stackoverflow.com
🌐 stackoverflow.com
JS Array.foreach vs for-loops, pros and cons, which do you use and why

If you want to do sequential async tasks, you can't use forEach, you need to use a for loop with await.

More on reddit.com
🌐 r/webdev
27
8
February 21, 2022
How to return a value from a forEach function (ES6)
Hi everyone, So I am trying to understand what I am doing wrong with my function. It’s just a silly function I’ve thrown together for learning purposes. index.html Element { console.log(a(item)); return a(item); }); console.log(test2); } init(); test.js const obj = { Chris: 'un... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
October 26, 2018
🌐
W3Schools
w3schools.com › JSREF › jsref_forEach.asp
W3Schools.com
The forEach() method calls a function for each element in an array.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › es6-array-foreach-method
ES6 | Array forEach() Method - GeeksforGeeks
December 13, 2021 - With forEach() Loop: In ES6 a more easy to understand and use method is introduced for Arrays which is forEach(). Let's see how it works for the same above situation. Program 2: javascript · <script> var array_1 = [2, 3, 4, 5, 6]; array_1.forEach(function(number, i) { array_1[i] *= 2; }); document.write(array_1); </script> Output: 4, 6, 8, 10, 12 ·
🌐
Mimo
mimo.org › glossary › javascript › foreach
JavaScript forEach(): Syntax, Usage, and Examples
Use JavaScript forEach() to loop through arrays and perform actions on each item—log data, update UI, or trigger functions easily.
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › looping in modern javascript: foreach and for...of
Looping in JavaScript ES5 and ES6 : forEach and for...of
December 13, 2024 - With ES5, we got a new method of looping over data. We can use ES5's forEach to iterate over the full array, like this:
Find elsewhere
🌐
Medium
medium.com › @odukoyaayodeji › old-road-town-for-loops-and-es6-foreach-helper-cbee84a04959
For Loop and es6 forEach() array helper | by Ayodeji Moses Odukoya | Medium
April 29, 2020 - The forEach() is an array helper method built into the array object in JavaScript. Just like we have other methods such as filter(), find(), map(), every(), some(), and reduce(). These methods which I will cover in subsequent articles are useful ...
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-use-foreach-in-javascript-ac26b0c533b0
How to use forEach in JavaScript. Learn how to use forEach, how it… | by Sunil Sandhu | JavaScript in Plain English
November 5, 2019 - The difference between a for loop and a forEach is that, in a for loop, you decide how many times you want the function to run, whereas a forEach loop will run as many times as there are items inside of the array that it is being used on.
🌐
Go Make Things
gomakethings.com › es6-foreach-loops-with-vanilla-javascript
ES6 forEach() loops with vanilla JavaScript | Go Make Things
March 8, 2018 - TheArray.forEach() ES6 introduced the Array.forEach() method for looping through arrays. You call this method on your array, and pass in a callback function to run on each iteration of the loop.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Map › forEach
Map.prototype.forEach() - JavaScript | MDN
The forEach() method of Map instances executes a provided function once per each key/value pair in this map, in insertion order.
🌐
TutorialsPoint
tutorialspoint.com › es6 › es6_array_method_foreach.htm
ES6 - Array Method forEach()
forEach() method calls a function for each element in the array. Returns created array.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Set › forEach
Set.prototype.forEach() - JavaScript | MDN
The forEach() method executes the provided callback once for each value which actually exists in the Set object. It is not invoked for values which have been deleted.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
How to return a value from a forEach function (ES6)
October 26, 2018 - Hi everyone, So I am trying to understand what I am doing wrong with my function. It’s just a silly function I’ve thrown together for learning purposes. index.html Element { console.log(a(item)); return a(item); }); console.log(test2); } init(); test.js const obj = { Chris: 'un...
🌐
Sololearn
sololearn.com › en › Discuss › 1793058 › foreach-iteration-in-es6
.forEach iteration in ES6 | Sololearn: Learn to code for FREE!
Lord Krishna Well, the forEach() method doesn't actually return anything (undefined). It simply calls a provided function on each element in your array. This callback is allowed to mutate the calling array.
🌐
SheCodes
shecodes.io › athena › 262218-can-you-use-foreach-with-an-array-of-objects
[JavaScript] - Can you use forEach with an array of | SheCodes
Learn how to use the forEach method in JavaScript to iterate over an array of objects and perform an action on each element.