Question 14
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const o = { a: 1, b: 2 };
console.log(Object.fromEntries(Object.entries(o).map(([k, v]) => [v, k])));
- A { 1: 'a', 2: 'b' }
- B { a: 1, b: 2 }
- C [ [ 1, 'a' ], [ 2, 'b' ] ]
- D { '1': 'a', '2': 'b' } Correct
Correct Answer: Option D
The numbers become string keys. Node shows numeric-looking keys in quotes to make clear that they are strings.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!