In some of the projects I\'m working on as part of my day job, I need to access data in very large JS objects (on the order of thousands of key-value pairs). I\'m trying to
Javascript objects are actually Hashes, so the complexity is O(1)
for all engines.
obj.field
is an alias for obj['field']
, so they have the same performances.
You can find some JS hashes performance tests here, unfortunately only for your browser engine.
In the worst case the complexity of a JS object lookup is O(1), it's the complexity of a hash table lookup. Unfortunately, your case is the worst one because you have so many items in the object. There is no difference how you access the property, obj.field
and obj['filed']
it's the same.
It's also worth to mention that the complexity isn't always equal to complexity of a hash table lookup, it's faster in much cases. Modern JS engines use techniques called hidden classes and inline caching to speed up the lookup. It's a pretty big question, how these techniques work, I've explained it in the another answer.
Some relative resources: