0
0
Javascriptprogramming~20 mins

Object entries in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Object Entries Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of Object.entries on a simple object?
Consider the following code snippet. What will be printed to the console?
Javascript
const obj = {a: 1, b: 2, c: 3};
console.log(Object.entries(obj));
A[['a', 1], ['b', 2], ['c', 3]]
B[['1', 'a'], ['2', 'b'], ['3', 'c']]
C[['a', '1'], ['b', '2'], ['c', '3']]
D[['a', 1, 'b', 2, 'c', 3]]
Attempts:
2 left
πŸ’‘ Hint
Object.entries returns an array of [key, value] pairs.
❓ Predict Output
intermediate
2:00remaining
What does Object.entries return for an object with symbol keys?
What will be the output of the following code?
Javascript
const sym = Symbol('id');
const obj = {a: 10, [sym]: 20};
console.log(Object.entries(obj));
A[]
B[['a', 10], [Symbol(id), 20]]
C[['a', 10], ['sym', 20]]
D[['a', 10]]
Attempts:
2 left
πŸ’‘ Hint
Object.entries only includes string keys, not symbol keys.
❓ Predict Output
advanced
2:00remaining
Output of Object.entries on an object with inherited properties
What will this code print?
Javascript
const parent = {x: 1};
const child = Object.create(parent);
child.y = 2;
console.log(Object.entries(child));
A[['y', 2]]
B[]
C[['x', 1], ['y', 2]]
D[['x', 1]]
Attempts:
2 left
πŸ’‘ Hint
Object.entries only lists own enumerable properties, not inherited ones.
❓ Predict Output
advanced
2:00remaining
What is the output of Object.entries on an array?
What will this code print?
Javascript
const arr = ['a', 'b', 'c'];
console.log(Object.entries(arr));
A[['a', 0], ['b', 1], ['c', 2]]
B[['0', 'a'], ['1', 'b'], ['2', 'c']]
C[['length', 3]]
D[]
Attempts:
2 left
πŸ’‘ Hint
Arrays are objects with keys as string indices.
🧠 Conceptual
expert
2:00remaining
Which option causes a TypeError when using Object.entries?
Which of the following code snippets will cause a TypeError when calling Object.entries?
AObject.entries([1,2,3])
BObject.entries({a:1})
CObject.entries(null)
DObject.entries('abc')
Attempts:
2 left
πŸ’‘ Hint
Object.entries expects an object, null is not an object.