Skip to main content

compact

Returns a copy of an object or array, with null and undefined values removed. Other falsy values — false, 0 and '' — are kept.

import { compact } from '@rvoh/dream/utils'

compact(['hello', null, undefined, 'world'])
// ['hello', 'world']

compact({ hello: 'world', goodbye: null })
// { hello: 'world' }

compact([0, false, '', null])
// [0, false, '']