forEachよりfor..ofを

  • forEachはes5から
  • for..ofはes6から

example

// bad
const arr = [2, 3, 5, 7, 11, 13];
arr.forEach(x => {
  console.log(x);
});

// good
const arr = [2, 3, 5, 7, 11, 13];
for (const x of arr) {
  console.log(x);
}

forEacheでできない部分

  • break

References

results matching ""

    No results matching ""