Reference ForEach

  • Will run the function for each element of the array.
  • This is a better option for achieving something based on the array element rather than creating a mutated array.
  • W3Schools Documentation Array ForEach

Example - Number of todos 200
WDS Video on this Hook
fetch("https://jsonplaceholder.typicode.com/todos") .then((response) => response.json()) .then((todos) => { let sum = 0; todos.forEach((t) => sum++); console.log(sum); });