Adding New Properties in object in javascript
You can add new properties to an existing object by simply giving it a value.
Assume that the person object already exists - you can then give it new properties:
const person = {
firstname: "John",
lastname: "Doe",
age: 50,
eyecolor: "blue"
};
person.nationality = "English";
console.log(person);
// output
{ firstname: 'John',
lastname: 'Doe',
age: 50,
eyecolor: 'blue',
nationality: 'English' }
Comments
Post a Comment