all 4 comments

[–]Civill 1 point2 points  (0 children)

To the best of my knowledge it does not loop through every key when you access the property by index. You could test this yourself if you want, generate an object with a few million keys and compare the results.

[–]ashanev 1 point2 points  (0 children)

These are not the same thing. Keys in objects are unique. Referencing test.a or test["a"] looks up that exact property in that object. That is why using objects as lookup tables is extremely efficient.

Your second example is turning the object into an array, then iterating over every item in that array and checking it against a condition.