Object Entries
Predict Output Medium
Question
What does this code print?
Code
let e = Object.entries({a: 1, b: 2});
console.log(e.length);
Hint
entries returns key-value pairs.
Explanation
Object.entries({a: 1, b: 2}) returns [["a", 1], ["b", 2]] — an array of key-value pairs. The length is 2 (two properties). This is useful for iterating over objects with for...of or map.
Related Resources
Related Lessons
- Objects
Learn JS objects.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.