0
0
Javascriptprogramming~5 mins

Object entries in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does Object.entries() do in JavaScript?

Object.entries() takes an object and returns an array of its own enumerable property [key, value] pairs.

Think of it like turning a box of labeled items into a list of label-item pairs.

Click to reveal answer
beginner
How is the output of Object.entries() structured?

The output is an array where each element is a two-item array: the first item is the property key (a string), and the second is the property value.

Example: [['name', 'Alice'], ['age', 30]]

Click to reveal answer
intermediate
Can Object.entries() be used on arrays? What happens?

Yes! Arrays are objects with numeric keys as strings. Object.entries() returns pairs of index and value.

Example: Object.entries(['a', 'b']) returns [['0', 'a'], ['1', 'b']].

Click to reveal answer
intermediate
Does Object.entries() include inherited properties?

No. It only includes the object's own enumerable properties, not those inherited from its prototype.

Click to reveal answer
beginner
How can Object.entries() help in looping over an object?
<p>You can use <code>Object.entries()</code> with <code>for...of</code> to get key and value in each loop step.</p><p>Example:<br><code>for (const [key, value] of Object.entries(obj)) { console.log(key, value); }</code></p>
Click to reveal answer
What does Object.entries({a: 1, b: 2}) return?
A{a: 1, b: 2}
B['a', 'b']
C[1, 2]
D[['a', 1], ['b', 2]]
Does Object.entries() include properties from the object's prototype?
ANo, only own enumerable properties
BYes, all properties
COnly non-enumerable properties
DOnly properties starting with underscore
What is the type of each element inside the array returned by Object.entries()?
AArray of two elements
BString
CNumber
DObject
What will Object.entries(['x', 'y']) return?
A[0, 1]
B[['0', 'x'], ['1', 'y']]
C['x', 'y']
D[]
Which loop works well with Object.entries() to access keys and values?
Afor...in
Bwhile
Cfor...of
Ddo...while
Explain how Object.entries() transforms an object and give a simple example.
Think about turning a labeled box into a list of label-item pairs.
You got /2 concepts.
    Describe how you can use Object.entries() to loop through an object's properties.
    Focus on how to get both key and value easily in a loop.
    You got /3 concepts.