当前位置:网站首页>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 '
}
边栏推荐
- Day22 deadlock, thread communication, singleton mode
- Common text processing tools
- test
- Grep of three swordsmen in text processing
- .Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
- 解决缓存击穿问题
- Cinnamon Applet 入门
- 达晨与小米投的凌云光上市:市值153亿 为机器植入眼睛和大脑
- Isprs2021/ remote sensing image cloud detection: a geographic information driven method and a new large-scale remote sensing cloud / snow detection data set
- Session
猜你喜欢

error LNK2019: 无法解析的外部符号

Awk of three swordsmen in text processing

MySQL master-slave replication

AUTOCAD——大于180度的角度标注、CAD直径符号怎么输入?

leecode3. 无重复字符的最长子串

Image pixel read / write operation

Day22 deadlock, thread communication, singleton mode

飞桨EasyDL实操范例:工业零件划痕自动识别

Leetcode question brushing: binary tree 26 (insertion operation in binary search tree)

.Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
随机推荐
滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
Day26 IP query items
regular expression
2022 examination questions and online simulation examination for safety production management personnel of hazardous chemical production units
How to reset Google browser? Google Chrome restore default settings?
详细介绍六种开源协议(程序员须知)
处理链中断后如何继续/子链出错removed from scheduling
人均瑞数系列,瑞数 4 代 JS 逆向分析
Unity build error: the name "editorutility" does not exist in the current context
Leetcode skimming: binary tree 21 (verifying binary search tree)
ORACLE进阶(五)SCHEMA解惑
Leetcode question brushing: binary tree 26 (insertion operation in binary search tree)
JS判断一个对象是否为空
Day-24 UDP, regular expression
MATLAB中polarscatter函数使用
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst
centso7 openssl 报错Verify return code: 20 (unable to get local issuer certificate)
Cmu15445 (fall 2019) project 2 - hash table details