Radash
  1. Array
  2. collect

Basic usage

Given an array and a transform function, returns a new array with each transformed element that does not evaluate to undefined.

import { collect } from 'radash'

const gods = [
  {
    name: 'Ra',
    culture: 'egypt'
  },
  {
    name: 'Zeus',
    culture: 'greek'
  },
  {
    name: 'Loki',
    culture: 'greek'
  }
]

collect(gods, g => (g.culture === 'greek' ? g.name.toUpperCase() : undefined)) // => ['ZEUS', 'LOKI']