当前位置:网站首页>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 '
}
边栏推荐
- .Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
- 日本政企员工喝醉丢失46万信息U盘,公开道歉又透露密码规则
- Practical case: using MYCAT to realize read-write separation of MySQL
- Ogre入门尝鲜
- 【Presto Profile系列】Timeline使用
- Session
- Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
- 2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)
- Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
- Day22 deadlock, thread communication, singleton mode
猜你喜欢
Day22 deadlock, thread communication, singleton mode
[untitled]
【无标题】
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
【Presto Profile系列】Timeline使用
高瓴投的澳斯康生物冲刺科创板:年营收4.5亿 丢掉与康希诺合作
Sequoia China completed the new phase of $9billion fund raising
【学习笔记】AGC010
HZOJ #240. Graphic printing IV
认养一头牛冲刺A股:拟募资18.5亿 徐晓波持股近40%
随机推荐
- Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
怎样重置火狐浏览器
Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)
Leetcode skimming: binary tree 21 (verifying binary search tree)
Four functions of opencv
红杉中国完成新一期90亿美元基金募集
Aosikang biological sprint scientific innovation board of Hillhouse Investment: annual revenue of 450million yuan, lost cooperation with kangxinuo
Ip2long and long2ip analysis
2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)
“新红旗杯”桌面应用创意大赛2022
Creation and assignment of graphic objects
10 张图打开 CPU 缓存一致性的大门
关于 appium 如何关闭 app (已解决)
共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf
学习突围2 - 关于高效学习的方法
What are the benefits of ip2long?
Practical case: using MYCAT to realize read-write separation of MySQL
DETR介绍
【Presto Profile系列】Timeline使用
线程池拒绝策略最佳实践