Skip to content

JS Update Object Properties

Syntax

Object properties in JavaScript can be updated using dot notation or bracket notation.

objectName.key = newValue; // Using dot notation
objectName["key"] = newValue; // Using bracket notation

Example

let person = {
name: "Alice",
age: 30,
isStudent: false
};
person.age = 31; // Update using dot notation
person["isStudent"] = true; // Update using bracket notation
console.log(person);
// Outputs: {name: "Alice", age: 31, isStudent: true}
person.job = "Engineer"; // Adds a new property
console.log(person); // Outputs: {name: "Alice", age: 30, isStudent: true, job: "Engineer"}