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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Vercel News
Vercel News
F
Fortinet All Blogs
B
Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
C
Check Point Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
Visual Studio Blog
月光博客
月光博客

博客园 - 炎峰森林影

安装 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
}

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