当前位置:网站首页>Determine whether an attribute exists in an object
Determine whether an attribute exists in an object
2022-06-28 05:20:00 【Zhangshao】
Determine whether an attribute exists in the object
Write it correctly
/** * Determine whether an attribute exists in the object * @param {Object} obj object * @param {Sting} key Property name */
function hasProperty(obj,key){
return key in obj;
}
Wrong writing
function hasProperty(obj,key){
return obj.key !== undefined; // The wrong way out.
}
function hasProperty(obj,key){
return obj[key] !== undefined; // The value of an attribute in an object cannot be determined to be undefined Properties of
}
Such as
var obj = {
a:undefined}
function hasProperty(obj,key){
return Object.keys(obj).includes(key)
}
// Unable to get usage defineProperty Properties added
Object.defineProperty(obj,'c',{
enumberable:false,
value: 1
})
function hasProperty(obj,key){
return obj.hasOwnProperty(key) // Unable to find data on prototype chain
}
边栏推荐
- 2022 safety officer-b certificate examination question bank and answers
- 活性染料研究:Lumiprobe AF594 NHS 酯,5-异构体
- 2022新版nft源码中国元宇宙数字藏品艺术品交易平台源码
- 交流电和直流电的区别是什么?
- lotus v1.16.0 calibnet
- metaRTC5.0 API编程指南(一)
- Unity out ref params
- 2022烟花爆竹经营单位安全管理人员特种作业证考试题库及模拟考试
- Study on chemical properties and technology of biovendor rage ELISA Kit
- RxSwift --(1)创建一个项目
猜你喜欢
![[Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer](/img/1f/becda82f3136678c58dd8ed7bec8fe.png)
[Verilog quick start of Niuke online question brushing series] ~ one out of four multiplexer

JS text box loses focus to modify width text and symbols

openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题

Docker安装Mysql5.7并开启binlog

Biovendor sRAGE protein solution

Learning Tai Chi Maker - mqtt Chapter 2 (V) heartbeat mechanism

羧酸研究:Lumiprobe 磺基花青7二羧酸

sqlmap工具使用手册

Share a powerful tool for factor Mining: genetic programming

CPG 固体支持物研究:Lumiprobe通用 CPG II 型
随机推荐
Dart学习——函数、类
How long will the PMP test results come out? You must know this!
metaRTC5.0编程之p2p网络穿透(stun)指南
Deeplearning ai-week1-quiz
【JVM系列】JVM调优
lotus v1.16.0 calibnet
sqlmap工具使用手册
【LeetCode】12、整数转罗马数字
PMP考试成绩多久出来?这些你务必知道!
Understanding the source of innovation II
店铺进销存管理系统源码
Sorting out some topics of modern exchange principle MOOC
【JVM】——JVM中内存划分
Store inventory management system source code
Metartc5.0 API programming guide (I)
Wedding studio portal applet based on wechat applet
If a programmer goes to prison, will he be assigned to write code?
msa. h: There is no such file or directory
cgo+gSoap+onvif学习总结:8、arm平台交叉编译运行及常见问题总结
DH parameters of robotics and derivation using MATLAB symbolic operation