当前位置:网站首页>Several methods of checking JS to judge empty objects
Several methods of checking JS to judge empty objects
2022-07-07 12:16:00 【InfoQ】
Knowledge preparation
Object.keys
Object.keys() var obj = {
name: "cxy",
age: "19"
};
var objArray = Object.getOwnPropertyNames(obj);
console.log(objArray)

objArrayObject.getOwnPropertyNames
Object.getOwnPropertyNames()Object.getOwnPropertyNames()Object.keys()Enumerable properties
enumerableobj.name = "cxy"enumerableturefalseforObject.keys()JSON.stringify()Object.getOwnPropertyNamesObject.keys()definePropertyagefalsevar stuObj = {
name: "cxy"
}
Object.defineProperty(stuObj, 'age', {
value: "18",
enumerable: false
});
console.log(Object.keys(stuObj))
console.log(Object.getOwnPropertyNames(stuObj))

hasOwnProperty
hasOwnProperty() var stuObj = {
name: "cxy"
}
console.log(stuObj.hasOwnProperty('name'))

hasOwnProperty()falsetoStringMethod of checking blank
JSON.stringify
Sentenced to empty
JSON.stringifylet obj = {
name: "cxy"
}
console.log(JSON.stringify(obj) == '{}')
for in
Sentenced to empty
for infalseturelet forNull = (items) => {
for (let item in items) {
return false
}
return true
}
Object.getOwnPropertyNames
Sentenced to empty
Object.getOwnPropertyNameslengthlet stuArray = Object.getOwnPropertyNames(obj)
console.log(stuArray.length === 0)
Object.keys()
Sentenced to empty
let stuArray = Object.getOwnPropertyNames(obj)
console.log(stuArray.length === 0)
hasOwnProperty
Sentenced to empty
hasOwnPropertyfalselet forNull = (items) => {
for (let item in items) {
if(items.hasOwnProperty(item)){
return false
}
}
return true
}
边栏推荐
- 111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
- Epp+dis learning road (2) -- blink! twinkle!
- 人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
- 108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
- Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
- Up meta - Web3.0 world innovative meta universe financial agreement
- 30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
- La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
- Cenos openssh upgrade to version 8.4
- SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
猜你喜欢

百度数字人度晓晓在线回应网友喊话 应战上海高考英语作文

Rationaldmis2022 advanced programming macro program

【神经网络】卷积神经网络CNN【含Matlab源码 1932期】

Up meta - Web3.0 world innovative meta universe financial agreement

人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》

Upgrade from a tool to a solution, and the new site with praise points to new value

MATLAB實現Huffman編碼譯碼含GUI界面

Complete collection of common error handling in MySQL installation

(待会删)yyds,付费搞来的学术资源,请低调使用!

18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)
随机推荐
开发一个小程序商城需要多少钱?
UP Meta—Web3.0世界创新型元宇宙金融协议
zero-shot, one-shot和few-shot
[filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Rationaldmis2022 advanced programming macro program
[shortest circuit] acwing 1127 Sweet butter (heap optimized dijsktra or SPFA)
DOM parsing XML error: content is not allowed in Prolog
SwiftUI Swift 内功之 Swift 中使用不透明类型的 5 个技巧
让数字管理好库存
【玩转 RT-Thread】 RT-Thread Studio —— 按键控制电机正反转、蜂鸣器
千人规模互联网公司研发效能成功之路
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full
Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool
【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
(待会删)yyds,付费搞来的学术资源,请低调使用!
即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战
超标量处理器设计 姚永斌 第8章 指令发射 摘录
EPP+DIS学习之路(2)——Blink!闪烁!