How to Modify a Property of an Object in JavaScript

To modifyproperty in JavaScript, you can use dot notation or bracket notation to assign the new value to the existing property.

let obj = {
  name: 'Krunal',
  age: 27,
  education: 'Engineer'


obj['age'] = 26;
obj['name'] = 'Ankit';
console.log('After modifying a property using square bracket');


{ name: 'Krunal', age: 27, education: 'Engineer' }
After modifying a property using square bracket
{ name: 'Ankit', age: 26, education: 'Engineer' }

To change a value of the existing property of an object, specify the object name followed by a square bracket, the name of the property you wish to change, an equals sign, and the new value you want to assign.

You can also use the dot syntax to attach the new values to the existing properties or change the values of existing properties.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.