function compact compact<T>(list: (T | null | undefined)[]): T[] Removes null and undefined values from a list. Examples Example 1 compact([1, null, 2, undefined, 3]); // [1, 2, 3] compact(["a", "", null, "b"]); // ["a", "", "b"] Type Parameters T Parameters list: (T | null | undefined)[] Return Type T[]