Sometimes, we want to add members to an existing object with JavaScript.
In this article, we’ll look at how to add members to an existing object with JavaScript.
How to add members to an existing object with JavaScript?
To add members to an existing object with JavaScript, we can assign a value to a property in the object.
For instance, we write:
const obj = {
fn1: () => {}
}
obj.fn2 = () => {};
console.log(obj)
We set obj.fn2
to a function to add fn2
as a property of obj
.
Conclusion
To add members to an existing object with JavaScript, we can assign a value to a property in the object.