How to check if a key exists in an object in javascript
This question already has an answer here:
Use the hasOwnProperty
call
if (!obj.hasOwnProperty(key)) {
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
你可以这样做:
var key = 'key1';
if (!('key1' in obj)) {
....
}
// or
if (!(key in obj)) {
}
链接地址: http://www.djcxy.com/p/26630.html
上一篇: 如何检查ajax是否存在?