惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
博客园 - 司徒正美
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
Vercel News
Vercel News
爱范儿
爱范儿
Last Week in AI
Last Week in AI
G
Google Developers Blog
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
D
DataBreaches.Net
博客园_首页
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
V
V2EX
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理

博客园 - 炎峰森林影

安装 OpenClaw(PowerShell) 安装卸载 WSL 基于Windows,Docker用法 [SSL]免费SSL证书,自动续期 [Python, PHP]存储单位转换 [MySQL]递归生成数据行 解决CSDN不登录就不能复制代码的问题 [BAT]批量提交到Git [网络搭建]Centos8 + Docker-CE + K8S(kubeadm) [Vue]对Vue,Vuex.store,mixins理解 [Android]keytool创建密钥 [JS]JavaScript this 的六道坎 [MSSQL]跨数据库查询 [Tensorflow]统计功效解析 [Tensorflow]设置双击打开*.ipynb文件 [MSSQL]刷新全部视图 [Python]if-else的多种简洁的写法 [Python]Python __iter__ 深入理解 [Go]VSCode安装GoLang插件依赖安装失败
[JS]判断值为空
炎峰森林影 · 2022-09-30 · via 博客园 - 炎峰森林影
const isEmpty = (val: any): boolean => {
    // 注意:
    // 1.number,bigint,boolean,symbol不参与判断
    // 2.typeof NaN => 'number'
    // 3.JSON.stringify(new Blob(['123'])) => '{}'

    if (val?.constructor.name === 'Blob')
        return !val.size

    // JSON.stringify(undefined) => undefined
    // JSON.stringify(null) => 'null'
    // JSON.stringify(NaN) => 'null'
    // JSON.stringify([]) => '[]'
    // JSON.stringify({}) => '{}'
    if ([undefined, 'null', '""', '[]', '{}'].includes(JSON.stringify(val)))
        return true

    return false
}

重复写真麻烦,想到新方法先记录下来,每次都回想真折磨