当前位置:网站首页>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 '
}
边栏推荐
- MySQL importing SQL files and common commands
- 学习突围2 - 关于高效学习的方法
- 非分区表转换成分区表以及注意事项
- Leetcode skimming: binary tree 20 (search in binary search tree)
- TPG x AIDU|AI领军人才招募计划进行中!
- 如何让electorn打开的新窗口在window任务栏上面
- .Net下极限生产力之efcore分表分库全自动化迁移CodeFirst
- 服务器到服务器 (S2S) 事件 (Adjust)
- Pay close attention to the work of safety production and make every effort to ensure the safety of people's lives and property
- 将数学公式在el-table里面展示出来
猜你喜欢

将数学公式在el-table里面展示出来

Leetcode skimming: binary tree 27 (delete nodes in the binary search tree)

Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]

Star Enterprise Purdue technology layoffs: Tencent Sequoia was a shareholder who raised more than 1billion
![《ASP.NET Core 6框架揭秘》样章[200页/5章]](/img/4f/5688c391dd19129d912a3557732047.jpg)
《ASP.NET Core 6框架揭秘》样章[200页/5章]

Image pixel read / write operation

DETR介绍

.Net下極限生產力之efcore分錶分庫全自動化遷移CodeFirst

Per capita Swiss number series, Swiss number 4 generation JS reverse analysis

关于 appium 启动 app 后闪退的问题 - (已解决)
随机推荐
抓细抓实抓好安全生产各项工作 全力确保人民群众生命财产安全
MATLAB中polarscatter函数使用
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
滑轨步进电机调试(全国海洋航行器大赛)(STM32主控)
@What is the difference between resource and @autowired?
处理链中断后如何继续/子链出错removed from scheduling
初学XML
《ASP.NET Core 6框架揭秘》样章[200页/5章]
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
非分区表转换成分区表以及注意事项
《ASP.NET Core 6框架揭秘》样章[200页/5章]
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
服务器到服务器 (S2S) 事件 (Adjust)
About how appium closes apps (resolved)
飞桨EasyDL实操范例:工业零件划痕自动识别
【Presto Profile系列】Timeline使用
基于鲲鹏原生安全,打造安全可信的计算平台
Day-24 UDP, regular expression
Awk of three swordsmen in text processing
环境配置篇