has property node js 1

has property node js

const object1 = {};
object1.property1 = 42;

console.log(object1.hasOwnProperty('property1'));
// expected output: true

console.log(object1.hasOwnProperty('toString'));
// expected output: false

console.log(object1.hasOwnProperty('hasOwnProperty'));
// expected output: false

Here is what the above code is Doing:
1. We create an object called object1.
2. We add a property called property1 to object1.
3. We use the hasOwnProperty() method to check if object1 has a property called property1.
4. We use the hasOwnProperty() method to check if object1 has a property called toString.
5. We use the hasOwnProperty() method to check if object1 has a property called hasOwnProperty.

Similar Posts