let user = {
name: "John",
age: 30,
description: function () {
console.log(`name: ${this.name} age: ${this.age}`);
},
name() {
console.log(`my name is ${name}`);
},
};
Note: there is 2 way to add a function in an object.
Note: this method of creating an object is known as
object literal, another method is the use of a constructor. Prefer using a constructor
user.name;
user.name();
// or
user["name"];
delete user.age;
Use for...in loop.
for (let key in object) {
// code
}
if (keyName in user) {...}
// or
if (user.keyName == undefined) {...}