Skip to content

compact

js
_.compact(array)

创建一个删除所有 falsey 值的数组。值 falsenull0""undefinedNaN 为 false。

¥Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.

新增于

¥Since

0.1.0

参数

¥Arguments

  1. array (数组):要压缩的数组。

    ¥array (Array): The array to compact.

返回

¥Returns

(数组):返回新的过滤值数组。

¥(Array): Returns the new array of filtered values.

示例

¥Example

js
_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]

Lodash v4.17 中文网 - 粤ICP备13048890号