Concept Flow - Object entries
Start with an object
Call Object.entries(obj)
Iterate over each key-value pair
Create array of [key, value
Return the array
This flow shows how Object.entries takes an object and returns an array of key-value pairs.
const obj = {a: 1, b: 2}; const entries = Object.entries(obj); console.log(entries);
| Step | Action | Object State | Result | Output |
|---|---|---|---|---|
| 1 | Define obj | {a: 1, b: 2} | Object created | |
| 2 | Call Object.entries(obj) | {a: 1, b: 2} | Array of entries created | [['a', 1], ['b', 2]] |
| 3 | Print entries | [['a', 1], ['b', 2]] | Output to console | [['a', 1], ['b', 2]] |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| obj | undefined | {a: 1, b: 2} | {a: 1, b: 2} | {a: 1, b: 2} |
| entries | undefined | undefined | [['a', 1], ['b', 2]] | [['a', 1], ['b', 2]] |
Object.entries(obj) returns an array of [key, value] pairs from obj.
Only own enumerable properties are included.
Useful for looping over object entries.
Result is an array of arrays.
Example: {a:1} → [['a',1]]