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
}
myObj.hasOwnProperty(myProp)
const employee = {
id: 1,
name: "Jhon",
salary: 5000
};
const isSalaryExist = "salary" in employee;
console.log(isSalaryExist); //true
const isGenderExist = "gender" in employee;
console.log(isGenderExist); //false
if ('field' in obj) {
}