Uji apakah properti ada javascript
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name'); // => true
hero.hasOwnProperty('realName'); // => false
f0ru0l0rd
const hero = {
name: 'Batman'
};
hero.hasOwnProperty('name'); // => true
hero.hasOwnProperty('realName'); // => false
myObj.hasOwnProperty(myProp)
let result = person.hasOwnProperty('firstName');
console.log(result); // true
Code language: JavaScript (javascript)
let person = {
firstName: 'John',
lastName: 'Doe'
};
let result = 'firstName' in person;
console.log(result); // true
result = 'age' in person;
console.log(result); // false
Code language: JavaScript (javascript)
let person = {
firstName: 'John',
lastName: 'Doe',
age: undefined
};
let result = person.age !== undefined;
console.log(result); // false
Code language: JavaScript (javascript)