当前位置:网站首页>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)
objArray
Object.getOwnPropertyNames
Object.getOwnPropertyNames()
Object.getOwnPropertyNames()
Object.keys()
Enumerable properties
enumerable
obj.name = "cxy"
enumerable
ture
false
for
Object.keys()
JSON.stringify()
Object.getOwnPropertyNames
Object.keys()
defineProperty
age
false
var 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()
false
toString
Method of checking blank
JSON.stringify
Sentenced to empty
JSON.stringify
let obj = {
name: "cxy"
}
console.log(JSON.stringify(obj) == '{}')
for in
Sentenced to empty
for in
false
ture
let forNull = (items) => {
for (let item in items) {
return false
}
return true
}
Object.getOwnPropertyNames
Sentenced to empty
Object.getOwnPropertyNames
length
let 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
hasOwnProperty
false
let forNull = (items) => {
for (let item in items) {
if(items.hasOwnProperty(item)){
return false
}
}
return true
}
边栏推荐
- 什么是局域网域名?如何解析?
- 112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
- 110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
- Present pod information to the container through environment variables
- SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
- 108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]
- Sonar:Cognitive Complexity认知复杂度
- Time bomb inside the software: 0-day log4shell is just the tip of the iceberg
- SwiftUI Swift 内功之 Swift 中使用不透明类型的 5 个技巧
- 30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
猜你喜欢
H3C HCl MPLS layer 2 dedicated line experiment
NPC Jincang was invited to participate in the "aerospace 706" I have an appointment with aerospace computer "national Partner Conference
Inverted index of ES underlying principle
超标量处理器设计 姚永斌 第8章 指令发射 摘录
即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战
PowerShell cs-utf-16le code goes online
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
30. Feed shot named entity recognition with self describing networks reading notes
112.网络安全渗透测试—[权限提升篇10]—[Windows 2003 LPK.DDL劫持提权&msf本地提权]
随机推荐
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
[extraction des caractéristiques de texture] extraction des caractéristiques de texture de l'image LBP basée sur le mode binaire local de Matlab [y compris le code source de Matlab 1931]
108.网络安全渗透测试—[权限提升篇6]—[Windows内核溢出提权]
Typescript interface inheritance
从工具升级为解决方案,有赞的新站位指向新价值
Improve application security through nonce field of play integrity API
平安证券手机行开户安全吗?
Mastering the new functions of swiftui 4 weatherkit and swift charts
超标量处理器设计 姚永斌 第10章 指令提交 摘录
La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
Epp+dis learning path (1) -- Hello world!
顶级域名有哪些?是如何分类的?
Hi3516 full system type burning tutorial
数据库系统原理与应用教程(011)—— 关系数据库
108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
C#中在路径前加@的作用
[neural network] convolutional neural network CNN [including Matlab source code 1932]