how to add new key valuepair inside object js code example
Example 1: js add key to object
// given
const obj = {
key1: value1,
key2: value2
};
// add pair
obj["key3"] = value3;
obj.key4 = value4;
Example 2: add new key value pair to object javascript
const person = {
name: "Elon Musk"
}
person.age = 49;
console.log(person);
// {name: "Elon Musk", age: 49}