sf-utils2 sf-utils2
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
  • 快速开始

  • 基础-Base

  • 对象-Object

  • 数组-Array✨✨✨

    • 序言 👏
    • uniq 【数组去重】
    • arrayToMap 【数组转成Map】
    • arrayToObj 【数组转成obj】
    • chunk 【数组切割】
    • compact 【去除数组中无效值】
    • remove 【数组中移除一个元素】
    • shuffle 【数组随机打乱】
    • groupBy 【分组】
    • compactIsNoNullable 【去除数组中null/undefined/NaN】
      • 1.示例
      • 2.入参说明
      • 3.源码
    • arrayDiff【比较数组差异】🔥🔥
    • differenceBy【获取新增数组】🔥
    • intersection 【数组交集】
    • matchSubListGroup
    • listToTree【列表转树形】🔥🔥🔥
    • treeToList【树型转列表】🔥🔥🔥
    • eachTree【遍历树形结构】🔥🔥🔥
    • filterTree【过滤树形结构】🔥🔥🔥
    • childNodesInList【列表中获取某个下所有后代节点】🔥
    • parentNodesInTree【tree中获取所有祖先节点】 🔥
    • formatStrategyIdsInTree【树形数据中只选中父节点】 🔥
    • range 【序号列表生成函数】
  • 方法-Function

  • 字符串-String

  • 数学-Math

  • 文件-Buffer

  • 节点-dom

  • 拓展

  • nodejs

目录

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.入参说明

参数 说明 类型 是否必填
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
上次更新: 2023/09/17, 22:58:23
groupBy 【分组】
arrayDiff【比较数组差异】🔥🔥

← groupBy 【分组】 arrayDiff【比较数组差异】🔥🔥→

Theme by Vdoing | Copyright © 2022-2025 bianpengfei
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×