Como verificar se a propriedade existe em um objeto no script java
if (obj.hasOwnProperty('prop')) {
// do something
}
Expensive Eland
if (obj.hasOwnProperty('prop')) {
// do something
}
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name'); // => true
hero.hasOwnProperty('realName'); // => false
var person = {'first_name': 'bill','age':20};
if ( person.hasOwnProperty('first_name') ) {
//person has a first_name property
}