当前位置:网站首页>JS determines whether an object is empty
JS determines whether an object is empty
2022-07-07 13:08:00 【Dax1_】
1. for…in
utilize for...in
Traversing objects , If the object has properties, return “ Non empty ”, Otherwise return to “ empty ”
function fn(obj) {
for (let key in obj) {
return ' Non empty '
}
return ' empty '
}
2. JSON.Stringify()
utilize JSON.stringify()
Serialize objects , If the result after serialization is {}
, Then the object is empty
function fn2(obj) {
let res = JSON.stringify(obj)
return res === '{}' ? ' empty ' : ' Non empty '
}
3. Object.keys()
utilize Object.keys()
Returns the self of a given object Enumerable properties Array of components , If you return an empty array , Then the given object is an empty object .
function fn3(obj) {
return Object.keys(obj).length === 0 ? ' empty ' : ' Non empty '
}
边栏推荐
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- 服务器到服务器 (S2S) 事件 (Adjust)
- [untitled]
- AUTOCAD——大于180度的角度标注、CAD直径符号怎么输入?
- What if the xshell evaluation period has expired
- Layer pop-up layer closing problem
- HZOJ #236. Recursive implementation of combinatorial enumeration
- Conversion from non partitioned table to partitioned table and precautions
- shell 批量文件名(不含扩展名)小写改大写
- Day26 IP query items
猜你喜欢
Smart cloud health listed: with a market value of HK $15billion, SIG Jingwei and Jingxin fund are shareholders
Leetcode skimming: binary tree 21 (verifying binary search tree)
Leetcode skimming: binary tree 25 (the nearest common ancestor of binary search tree)
Sed of three swordsmen in text processing
Practical example of propeller easydl: automatic scratch recognition of industrial parts
智云健康上市:市值150亿港元 SIG经纬与京新基金是股东
【学习笔记】AGC010
About the problem of APP flash back after appium starts the app - (solved)
通过Keil如何查看MCU的RAM与ROM使用情况
“新红旗杯”桌面应用创意大赛2022
随机推荐
PACP学习笔记一:使用 PCAP 编程
Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)
The URL modes supported by ThinkPHP include four common modes, pathinfo, rewrite and compatibility modes
[untitled]
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
2022 polymerization process test question simulation test question bank and online simulation test
Leetcode skimming: binary tree 27 (delete nodes in the binary search tree)
Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
【无标题】
Shortcut key of Bash
Blog recommendation | Apache pulsar cross regional replication scheme selection practice
2022 examination questions and online simulation examination for safety production management personnel of hazardous chemical production units
企业级自定义表单引擎解决方案(十二)--体验代码目录结构
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
Conversion from non partitioned table to partitioned table and precautions
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
[learn microservices from 0] [03] explore the microservice architecture
分屏bug 小记
Practical example of propeller easydl: automatic scratch recognition of industrial parts
regular expression