当前位置:网站首页>判断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
边栏推荐
- 哈夫曼树(一)基本概念与C语言实现
- 哈夫曼樹(一)基本概念與C語言實現
- Lumiprobe无铜点击化学解决方案
- Jenkins打包拉取不到最新的jar包
- PHP require/include 区别
- PHP obtains opcode and C source code
- On inline function
- Summary of PHP file upload (garbled code, move failure, permission, display picture)
- 北京大学ACM Problems 1001:Exponentiation
- Notes on modification of Jerry's test box pairing software [chapter]
猜你喜欢

maya房子建模

Halcon知识:盘点一下计量对象【1】

By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry

Document contains & conditional competition

基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享

STL的基本组成部分

杰理之触摸按键识别流程【篇】

Introduction to neural network (Part 1)

NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer

Lumiprobe 改性三磷酸盐丨生物素-11-UTP研究
随机推荐
请问海量数据如何去取最大的K个
Basic components of STL
Pytorch implements the calculation of flops and params
Heartbeat and DRBD configuration process
B_QuRT_User_Guide(31)
C文件指针
maya房子建模
Maya house modeling
Informatics Olympiad 1362: family problems
北京大学ACM Problems 1003:Hangover
Openfire在使用MySQL数据库后的中文乱码问题解决
信息学奥赛一本通 1362:家庭问题(family)
北京大学ACM Problems 1006:Biorhythms
Jerry's touch key recognition process [chapter]
Lumiprobe copper free click chemical solution
谈谈内联函数
HeartBeat基于CRM使用NFS对MySQL高可用
Static classes use @resource annotation injection
Big God explains open source buff gain strategy live broadcast
Lumiprobe细胞生物学丨DiA,亲脂性示踪剂说明书