当前位置:网站首页>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
}
边栏推荐
- lotus v1.16.0 calibnet
- Function reentry caused by Keil C51's data overlaying mechanism
- What are functions in C language? What is the difference between functions in programming and functions in mathematics? Understanding functions in programming languages
- 羧酸研究:Lumiprobe 磺基花青7二羧酸
- Opencv实现颜色检测
- MySQL 45讲 | 05 深入浅出索引(下)
- metaRTC5.0编程之p2p网络穿透(stun)指南
- 通过例子学习Rust
- Carboxylic acid study: lumiprobe sulfoacyanine 7 dicarboxylic acid
- 如何从零设计一款牛逼的高并发架构(建议收藏)
猜你喜欢

WordPress zibll sub theme 6.4.1 happy version is free of authorization

【Linux】——使用xshell在Linux上安装MySQL及实现Webapp的部署

Operation of simulated examination platform of G3 boiler water treatment recurrent training question bank in 2022

基于微信小程序的婚纱影楼门户小程序

Lumiprobe cell imaging analysis: PKH26 cell membrane labeling kit

学习太极创客 — MQTT 第二章(六)MQTT 遗嘱

Cgo+gsoap+onvif learning summary: 8. Summary of arm platform cross compilation operation and common problems

Based on the order flow tool, what can we see?

店铺进销存管理系统源码

Dart learning - functions, classes
随机推荐
2022电力电缆判断题模拟考试平台操作
Liuhaiping's mobile phone passes [[uiapplication sharedapplication] delegate] window. safeAreaInsets. The height of the bottom security zone is 0
Learn Taiji Maker - mqtt Chapter 2 (IV) esp8266 reserved message application
并发之wait/notify说明
如何学习可编程逻辑控制器(PLC)?
交流电和直流电的区别是什么?
SlicePlane的Heading角度与Math.atan2(y,x)的对应转换关系
基于订单流工具,我们能看到什么?
Informatics Orsay all in one 1360: strange lift
wordpress zibll子比主题6.4.1开心版 免授权
[leetcode] 12. Integer to Roman numeral
【JVM】——JVM中内存划分
【JVM】——JVM中內存劃分
2022 high altitude installation, maintenance and removal examination questions and answers
lotus v1.16.0 calibnet
通过例子学习Rust
Operation of simulated examination platform of G3 boiler water treatment recurrent training question bank in 2022
Extjs library management system source code intelligent library management system source code
Don't roll! How to reproduce a paper with high quality?
CPG 固体支持物研究:Lumiprobe通用 CPG II 型