javascript update object property code example
Example 1: how to add property to object in javascript
var data = {
'PropertyA': 1,
'PropertyB': 2,
'PropertyC': 3
};
data["PropertyD"] = 4;
alert(data.PropertyD);
alert(data["PropertyD"]);
Example 2: JavaScript: Updating Object Properties
var myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["freeCodeCamp Campers"]
};
myDog.name = "Happy Coder";
Example 3: how to update object in javascript
myObject['first name'] = 'John';
Example 4: how to change object property value in javascript
myObject.sProp = 'A new string value for our original string property';