Removes all nullable values from an array.
const a = [1, null, 2, undefined, 3, 4, 5, null, 6];const b = compact(a);console.log(b); // [1, 2, 3, 4, 5, 6] Copy
const a = [1, null, 2, undefined, 3, 4, 5, null, 6];const b = compact(a);console.log(b); // [1, 2, 3, 4, 5, 6]
The type of the input array.
The array to compact.
A new array with nullable values removed.
Removes all nullable values from an array.
Example