Answers for "js filter array null"

2

typescript filter array of null

function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
    return value !== null && value !== undefined;
}

const array: (string | null)[] = ['foo', 'bar', null, 'zoo', null];
const filteredArray: string[] = array.filter(notEmpty);
Posted by: Guest on January-15-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language