Checking Property Existence
JS · Objectssyntax
Object.hasOwn(obj, prop)
"prop" in objexample
const user = { name: "Lina", age: 28 };
console.log(Object.hasOwn(user, "name")); // true
console.log(Object.hasOwn(user, "email")); // false
console.log("toString" in user); // true (inherited)
console.log(Object.hasOwn(user, "toString")); // falseNote Object.hasOwn() (ES2022) replaces obj.hasOwnProperty(). It works even if the object was created with Object.create(null).