Skip to content

sift

Remove all falsy items from list

62 bytes

Usage

Given a list of items, return a new list with all items that are not falsy.

import * as
import _
_
from 'radashi'
const
const fish: (string | number | boolean | null)[]
fish
= ['salmon', null, false,
var NaN: number
NaN
, 'sockeye', 'bass']
import _
_
.
sift<string | number | true>(array: readonly (string | number | boolean | 0n | null | undefined)[]): (string | number | true)[]
export sift

Given a list returns a new list with only truthy values.

@seehttps://radashi.js.org/reference/array/sift

@example

sift([0, 1, undefined, null, 2, false, 3, ''])
// => [1, 2, 3]

@version12.1.0

sift
(
const fish: (string | number | boolean | null)[]
fish
) // => ['salmon', 'sockeye', 'bass']