Object (JavaScript)
An object is a collection of related data stored as key/value pairs. Objects are the main way JavaScript groups properties and behavior together.
JavaScript
Each entry in an object has a key (the name) and a value, which can be any type including functions. You read values with dot notation (obj.key) or brackets (obj["key"]).
Objects are the foundation of almost everything in JavaScript, including arrays and JSON data.
Syntax
const obj = { key: value, key2: value2 };Examples
JavaScript
const car = { make: "Toyota", year: 2022 };
console.log(car.make);
car.color = "blue";
console.log(car.color);Output:
Toyota
blue