DEV Community

Discussion on: Much needed filterMap in JavaScript

Collapse
 
iliasbhal profile image
ilias bhallil • Edited

There is the flatMap method that does exactly that filter + map :)
this method not only lets you dynamically filter the array, but it also gives the ability to add elements to the array dynamically.

developer.mozilla.org/en-US/docs/W...

// example
someArray.flatMap((element) => {
  if(element.isNotNeeded){
    return [];
  }

  return [ element.someProperty ];
})