The JavaScript Object object
The Object is JavaScript's key-value structure — properties mapping names to values. Create one with a literal { name: "Ada" }. Read or loop its data with the static helpers Object.keys(), Object.values() and Object.entries(), and merge objects with Object.assign() or the spread operator.
Overview
The Object is the fundamental key-value structure in JavaScript — a bag of named properties. You create one with a literal: const user = { name: "Ada", age: 36 }. Read properties with dot notation (user.name) or brackets for dynamic keys (user[key]), add new ones by assigning, and remove them with delete. Values can be anything: numbers, strings, arrays, functions, other objects.
Because plain objects don't have map() or forEach(), the Object constructor provides static helpers to bridge to arrays: Object.keys() gives the property names, Object.values() gives the values, and Object.entries() gives [key, value] pairs you can loop with for...of. To merge objects, Object.assign() or the spread syntax {...a, ...b} do the job.
A couple more useful members: Object.freeze() makes an object read-only, and Object.hasOwn(obj, key) checks for an own property. When you need true key-value mapping with non-string keys, ordered iteration or frequent additions and deletions, a Map is sometimes a better fit than a plain object — but for structured records, the object literal is the everyday default.
Syntax
const user = { name: "Ada", age: 36 };
user.name; // "Ada"
user["age"]; // 36
user.role = "admin"; // add
delete user.age; // remove
Object.keys(user); // ["name", "role"]
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const book = { title: 'JS Guide', pages: 320, author: 'Ada' };
const summary = Object.entries(book)
.map(([key, value]) => key + ': ' + value)
.join('\n');
document.getElementById('out').textContent = summary;
</script>
Best practices
- Create objects with literals
{}and access properties with dot notation where possible. - Loop with Object.entries() (or keys()/
values()) to use array methods on object data. - Merge with the spread syntax
{...a, ...b}or Object.assign(). - Consider a
Mapwhen you need non-string keys, ordering guarantees or frequent add/remove.
Frequently asked questions
How do I create an object in JavaScript?
const obj = { key: "value" }. Read properties with obj.key or obj["key"].How do I loop over an object?
How do I merge two objects?
{...a, ...b} or Object.assign({}, a, b). Later properties win.What is the difference between an object and a Map?
Map allows any key type, preserves insertion order and is better for frequent additions and deletions.