JavaScript · Senior · Question 20 of 75
In what order will Object.keys return the keys of { b: 1, 2: 1, a: 1, 1: 1 }?
- ✓Correct answer:
['1', '2', 'b', 'a'] - 2
['b', '2', 'a', '1'] - 3
['a', 'b', '1', '2']
Explanation
Integer keys come first in ascending order, then string keys in insertion order, then symbols (which Object.keys doesn't return). If order matters for numeric keys, use a Map.