Snippets Collections
Not all browsers support forEach on NodeLists, but for those that do:

buttons.forEach((button) => {
  button.addEventListener('click', () => {
    console.log("forEach worked");
  });
});

bit deeper browser support.

var divs = document.querySelectorAll('div');
[].forEach.call(divs, function(div) {
  // do whatever
  div.style.color = "red";
});
JS

favMovies.forEach(function(favMovie) {
  console.log('I really like the movie', favMovie)
})
star

Mon Feb 13 2023 06:26:34 GMT+0000 (Coordinated Universal Time) https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/

#javascript #foreach
star

Sat Jan 15 2022 19:15:38 GMT+0000 (Coordinated Universal Time)

#python #javascript #iteration #foreach

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension