0
0
Javascriptprogramming~10 mins

Object entries in Javascript - Step-by-Step Execution

Choose your learning style9 modes available
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.
Execution Sample
Javascript
const obj = {a: 1, b: 2};
const entries = Object.entries(obj);
console.log(entries);
This code converts an object into an array of its key-value pairs and prints it.
Execution Table
StepActionObject StateResultOutput
1Define obj{a: 1, b: 2}Object created
2Call Object.entries(obj){a: 1, b: 2}Array of entries created[['a', 1], ['b', 2]]
3Print entries[['a', 1], ['b', 2]]Output to console[['a', 1], ['b', 2]]
💡 All object entries processed and output printed.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
objundefined{a: 1, b: 2}{a: 1, b: 2}{a: 1, b: 2}
entriesundefinedundefined[['a', 1], ['b', 2]][['a', 1], ['b', 2]]
Key Moments - 3 Insights
Why does Object.entries return an array of arrays instead of an object?
Object.entries returns an array because it represents each key-value pair as a two-element array, making it easy to iterate over with loops like for...of. This is shown in execution_table step 2 where the result is an array of [key, value] pairs.
Does Object.entries include inherited properties?
No, Object.entries only includes the object's own enumerable properties, not inherited ones. This is why the object state in execution_table step 1 matches exactly the entries in step 2.
What happens if the object is empty?
If the object is empty, Object.entries returns an empty array. This means no entries to iterate over, similar to execution_table but with an empty result array.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'entries' after step 2?
A[['a', 1], ['b', 2]]
B{a: 1, b: 2}
Cundefined
D['a', 'b']
💡 Hint
Check the 'Result' and 'Output' columns in execution_table row for step 2.
At which step is the array of key-value pairs created?
AStep 1
BStep 3
CStep 2
DNever
💡 Hint
Look at the 'Action' and 'Result' columns in execution_table to find when Object.entries is called.
If the object had an inherited property, would it appear in the entries array?
AYes, all properties appear
BNo, only own enumerable properties appear
COnly inherited properties appear
DOnly non-enumerable properties appear
💡 Hint
Refer to key_moments about inherited properties and execution_table step 2.
Concept Snapshot
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]]
Full Transcript
We start with an object that has some properties. When we call Object.entries on it, JavaScript creates an array where each element is a two-item array: the key and its value. This array is easy to loop over or use in other array methods. The entries only include the object's own properties, not those inherited from its prototype. Finally, printing the entries shows the array of key-value pairs.