Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function mapNotNullish
import { mapNotNullish } from "https://deno.land/std@0.147.0/collections/mod.ts";

Returns a new array, containing all elements in the given array transformed using the given transformer, except the ones that were transformed to null or undefined

Example:

import { mapNotNullish } from "https://deno.land/std@0.147.0/collections/map_not_nullish.ts";
import { assertEquals } from "https://deno.land/std@0.147.0/testing/asserts.ts";

const people = [
    { middleName: null },
    { middleName: 'William' },
    { middleName: undefined },
    { middleName: 'Martha' },
]
const foundMiddleNames = mapNotNullish(people, it => it.middleName)

assertEquals(foundMiddleNames, [ 'William', 'Martha' ])

Parameters

array: readonly T[]
transformer: (el: T) => O

Returns

NonNullable<O>[]