当前位置:网站首页>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
}
边栏推荐
- Superscalar processor design yaoyongbin Chapter 9 instruction execution excerpt
- [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]
- 110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
- Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
- Sort out the garbage collection of JVM, and don't involve high-quality things such as performance tuning for the time being
- Improve application security through nonce field of play integrity API
- 【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
- Epp+dis learning path (1) -- Hello world!
- idea 2021中文乱码
- 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中SmoothStep介绍和应用: 溶解特效优化
《通信软件开发与应用》课程结业报告
Camera calibration (2): summary of monocular camera calibration
Sonar:Cognitive Complexity认知复杂度
Fleet tutorial 14 basic introduction to listtile (tutorial includes source code)
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
即刻报名|飞桨黑客马拉松第三期盛夏登场,等你挑战
@What happens if bean and @component are used on the same class?
HCIA复习整理
随机推荐
TypeScript 接口继承
MATLAB實現Huffman編碼譯碼含GUI界面
Sonar:cognitive complexity
<No. 8> 1816. Truncate sentences (simple)
NGUI-UILabel
Upgrade from a tool to a solution, and the new site with praise points to new value
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
软件内部的定时炸弹:0-Day Log4Shell只是冰山一角
Fleet tutorial 14 basic introduction to listtile (tutorial includes source code)
让数字管理好库存
30. Feed shot named entity recognition with self describing networks reading notes
C#中在路径前加@的作用
平安证券手机行开户安全吗?
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
PowerShell cs-utf-16le code goes online
Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration
30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
盘点JS判断空对象的几大方法
[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]