当前位置:网站首页>判断js对象是否为空的方式
判断js对象是否为空的方式
2022-06-30 20:16:00 【草莓味巧克力豆】
三种判断方式:
1,使用for…in 进行遍历,如果返回true就是非空对象,否则为空对象
for(let i in obj){
return true
}
return false
2,通过JSON自带的stringify() 方法来进行判断
判断下面的表达式是否是正确的?
JSON.stringify(data) === ‘{
}’,如果是,那就是空对象,否则不是空对象
这里为什么不能使用toString()方法呢?
因为使用toString方法,即使是空对象,它也会输出[object,object]
3,ES6新增的方法 Object.keys(),这个方法通过判断它的长度来知道该对象是否为空。
Object.keys(obj).length
边栏推荐
猜你喜欢

To eliminate bugs, developers must know several bug exploration and testing artifacts.

MySQL:SQL概述及数据库系统介绍 | 黑马程序员

Implementation principle of PostgreSQL heap table storage engine

断点续传和下载原理分析

Study on PEGylation of lumiprobe and PEG linker - iodine-peg3-acid

Build your own website (20)

A complete collection of vulnerability scanning tools. Mom doesn't have to worry that I won't find any more vulnerabilities

On the charm of code language
![Jerry's touch key recognition process [chapter]](/img/3e/bb73c735d0a7c7a26989c65a432dad.png)
Jerry's touch key recognition process [chapter]

STL的基本组成部分
随机推荐
Jerry's question about long press boot detection [chapter]
Jerry's determination of detection sensitivity level [chapter]
Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒
北京大学ACM Problems 1003:Hangover
DEX文件解析 - method_ids解析
基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
Jerry's touch key recognition process [chapter]
Go learning notes
北京大学ACM Problems 1004:Financial Management
《大厂面试》之JVM篇21问与答
左值引用和右值引用
SQL必需掌握的100个重要知识点:创建和操纵表
Study on lumiprobe modified triphosphate biotin-11-utp
信息学奥赛一本通 1362:家庭问题(family)
Analysis of breakpoint continuation and download principle
Study on lumiprobe dye NHS ester BDP FL NHS ester
AVL平衡二叉树(一) - 概念与C语言实现
大神详解开源 BUFF 增益攻略丨直播
Lingyun going to sea | 10 leap &huawei cloud: jointly helping Africa with inclusive financial services
第81场双周赛