Jak sprawdzić, czy obiekt istnieje w JavaScript
if (typeof maybeObject != "undefined") {
alert("GOT THERE");
}
Smiling Stoat
if (typeof maybeObject != "undefined") {
alert("GOT THERE");
}
let result = targetObject.hasOwnProperty(propertyName);
let person = {
firstName: 'John',
lastName: 'Doe'
};
//Example 1
let result = person.hasOwnProperty('firstName');
console.log(result); // true
//Example 2
let result = person.hasOwnProperty('age');
console.log(result); // false
let result = person.hasOwnProperty('firstName');
console.log(result); // true
Code language: JavaScript (javascript)