当前位置:网站首页>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
}
边栏推荐
- The function of adding @ before the path in C #
- C#中在路径前加@的作用
- [filter tracking] strapdown inertial navigation pure inertial navigation solution matlab implementation
- Introduction to three methods of anti red domain name generation
- [data clustering] realize data clustering analysis based on multiverse optimization DBSCAN with matlab code
- 30. Feed shot named entity recognition with self describing networks reading notes
- EPP+DIS学习之路(1)——Hello world!
- Visual studio 2019 (localdb) \mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports version 782 and earlier
- 源代码防泄密中的技术区别再哪里
- What is a LAN domain name? How to parse?
猜你喜欢
Sonar:cognitive complexity
[shortest circuit] acwing 1127 Sweet butter (heap optimized dijsktra or SPFA)
Sonar:Cognitive Complexity认知复杂度
Superscalar processor design yaoyongbin Chapter 9 instruction execution excerpt
Review and arrangement of HCIA
《通信软件开发与应用》课程结业报告
La voie du succès de la R & D des entreprises Internet à l’échelle des milliers de personnes
SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
@What happens if bean and @component are used on the same class?
Inverted index of ES underlying principle
随机推荐
2022年在启牛开华泰的账户安全吗?
SwiftUI 教程之如何在 2 秒内实现自动滚动功能
Epp+dis learning road (2) -- blink! twinkle!
The Oracle message permission under the local Navicat connection liunx is insufficient
[neural network] convolutional neural network CNN [including Matlab source code 1932]
Time bomb inside the software: 0-day log4shell is just the tip of the iceberg
MATLAB实现Huffman编码译码含GUI界面
超标量处理器设计 姚永斌 第9章 指令执行 摘录
Flet教程之 15 GridView 基础入门(教程含源码)
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
消息队列消息丢失和消息重复发送的处理策略
PowerShell cs-utf-16le code goes online
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full
Introduction and application of smoothstep in unity: optimization of dissolution effect
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Is it safe to open Huatai's account in kainiu in 2022?
《通信软件开发与应用》课程结业报告
NGUI-UILabel