Fundamentals
Objects & object methods
Working with key-value data and the built-in Object helpers.
Objects store keyed collections of values and are the backbone of most JavaScript data.
An object is a labelled drawer unit; the reference is the address of the unit, not a photocopy of its contents.
Key concepts
1
Object.keys, Object.values and Object.entries turn an object into arrays you can iterate. Object.assign and the spread operator copy and merge objects. Object.freeze makes an object immutable.
Object.keysObject.valuesObject.entriesObject.assignObject.freeze
2
Remember that objects are held by reference — copying a variable copies the pointer, not the data, so mutating one copy mutates them all unless you clone.
reference
javascript
const user = { name: 'Ada', role: 'admin' };
Object.keys(user); // ['name', 'role']
Object.entries(user); // [['name','Ada'], ['role','admin']]
const copy = { ...user, role: 'editor' }; // shallow clone + override
Object.freeze(user); // user is now immutable