Algorithms and Data Structures · Junior · Question 66 of 75
What is the complexity of looking up a key in a plain JavaScript object, obj[key]?
- 1O(n) in all cases
- 2O(log n) on average
- ✓Correct answer: O(1) on average
Explanation
Engines store object properties in hash-table-like structures (or hidden classes for stable shapes), so access is constant time on average, just like Map.