Function: compact()
ts
function compact<T>(array): T[];Removes all falsy values from an array. 移除数组中的所有假值。
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of array items / 数组元素类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | The source array / 源数组 |
Returns
T[]
A new array without falsy values / 移除假值后的新数组
Example
ts
compact([0, 1, false, '', 2, null, undefined])
// => [1, 2]Since
1.2.0