compactIsNoNullable 【去除数组中null/undefined/NaN】
描述
去除数组中null/undefined/NaN 3.0.24-beta-3+
# 1.示例
import { compactIsNoNullable } from 'sf-utils2'
compactIsNoNullable([0, 1, '', 2, {}, [], null, undefined, NaN]) => [0, 1, 2, '', {}, []]
1
2
3
2
3
# 2.入参说明
| 参数 | 说明 | 类型 | 是否必填 |
|---|---|---|---|
| array | 原数组 | Array | 是 |
# 3.源码
/**
* 去除数组中的 是null 、undefined、NaN
* @param {Array} array
* @return {any[]}
* @example
* compactIsNoNullable[0, 1, '', 2, {}, [], null, undefined, NaN]
* =>
* [0, 1, 2, '', {}, []]
*/
function compactIsNoNullable(array) {
if (!isArray(array)) array = Array.from(array)
return array.filter(v => isNoNullable(v) || !isNaN(v))
}
export default compactIsNoNullable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
上次更新: 2023/09/17, 22:58:23