AlvinfromDiaspar
AlvinfromDiaspar

Reputation: 6834

Javascript performance of indexing

Is the following line considered unoptimal, especially considering it is being used in many places or inside of a loop:

var age = myObject[index]["Person"]["Identity"]["Bio"]["Age"]

Upvotes: 0

Views: 85

Answers (1)

Henrique Barcelos
Henrique Barcelos

Reputation: 7900

Even if hash lookup in Javascript is O(1) (I don't know for sure), you'd still have the overhead of the lookup operations. So, yes, this is suboptimal for a big loop.

Upvotes: 1

Related Questions