Typorithm · easy

Object keys, values, entries

object-iteratecollectionsobjectsiteratemerge
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Object keys, values, entries

0%

Objects & Maps

Object.keys, Object.values, and Object.entries turn a plain object into iterable arrays. Object.entries pairs nicely with destructuring in map; merge objects with Object.assign({}, a, b) or spread { ...a, ...b }.

Plain objects are not directly iterable, so you bridge to arrays: Object.keys gives names, Object.values gives values, and Object.entries gives [key, value] pairs.

Object.entries(obj).map(([k, v]) => ...) destructures each pair, which is the idiomatic way to loop over an object's data.

To combine objects, Object.assign({}, a, b) copies sources into a fresh target, and the spread form { ...a, ...b } does the same more concisely — in both, later sources overwrite earlier keys.

01

Object.keys / values / entries expose object data as arrays.

02

Destructure entries with .map(([k, v]) => ...).

03

Merge with Object.assign({}, a, b) or { ...a, ...b }.

const user = { name: "Ada", age: 36, role: "admin" }
const keys = Object.keys(user)
const values = Object.values(user)
const pairs = Object.entries(user).map(([k, v]) => `${k}=${v}`)
const merged = Object.assign({}, user, { age: 37 })
const spread = { ...user, role: "editor" }

Read the implementation

Connect each part of the code to the concept before you type.

1. Keys array

Object.keys returns an array of the object's own enumerable property names.

Object.keys(user)

2. Values array

Object.values returns an array of the corresponding property values.

Object.values(user)

3. Entries + destructure

Object.entries yields [key, value] pairs you can destructure inside map.

Object.entries(user).map(([k, v]) => `${k}=${v}`)

4. Merge with assign

Object.assign copies sources left to right into the target; later sources win.

Object.assign({}, user, { age: 37 })

5. Merge with spread

Spread copies own enumerable properties; later entries override earlier ones.

{ ...user, role: "editor" }

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Object keys, values, entries: Lesson & Practice · Typorithm | ApplyDjinn