loading...

re: Sets in ES6 - A Quick Guide VIEW POST

TOP OF THREAD FULL DISCUSSION
re: The third value is the current Set you're iterating over. A number of methods have this argument, and I've never figured out why This allows you ...
 

More than that! You need it if you chain methods like so:

myArr
  .filter(val => !!val)
  .forEach((val, idx, filteredArr) => {
    // now has access to the filtered array via `filteredArr`
  })
  .map((val, idx, filteredArr) => {

  })
  .forEach((val, idx, mappedArr) => {
    // now has access to the filtered and mapped array via `mappedArr`
  });

Otherwise, you'd have to execute and assign these to variables and reach out of the inner scope of the call back function.

code of conduct - report abuse