当前位置:网站首页>判断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
边栏推荐
- Lumiprobe染料酰肼丨BDP FL 酰肼方案
- Testing principle and precautions of biovendor rage ELISA Kit
- Lumiprobe 聚乙二醇化和 PEG 接头丨碘-PEG3-酸研究
- Is it safe to open an account for online stock trading!?
- 大神詳解開源 BUFF 增益攻略丨直播
- Lumiprobe protein quantitation - qudye Protein Quantitation Kit
- Peking University ACM problems 1000:a+b problem
- Lingyun going to sea | 10 leap &huawei cloud: jointly helping Africa with inclusive financial services
- Implementation principle of PostgreSQL heap table storage engine
- Informatics Olympiad 1362: family problems
猜你喜欢
随机推荐
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
Lumiprobe细胞生物学丨DiA,亲脂性示踪剂说明书
How do I get the largest K massive data
AVL balanced binary tree (I) - concept and C language implementation
浅谈代码语言的魅力
Lambda expression principle analysis and learning (June 23, 2022)
杰理之触摸按键识别流程【篇】
Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒
Web host iptables firewall security script
Comparison between QT and other GUI Libraries
Basic concepts of tree
Encoding type of Perl conversion file
为什么vscode用久了电脑速度变慢?
QT qstringlist usage
BioVendor sRAGE Elisa试剂盒测试原理和注意事项
杰理之检测灵敏度级别确定【篇】
Static classes use @resource annotation injection
On the charm of code language
1. Introduction to generating countermeasures network
Playwright - scroll bar operation









