Assign object[key] to a temp variable in a javascript “for…in” loop?

前端 未结 1 520
名媛妹妹
名媛妹妹 2020-12-20 04:15

I\'m working on a JS to show different messages depending on the current url\'s hash. Now, that\'s all working, but I was wondering what the best way would be to access my m

相关标签:
1条回答
  • 2020-12-20 04:50

    It turns out it is indeed faster to assign your object[key] to a temporary variable in for-in loops with large objects, as seen in this jsPerf test. That way, you won't have to obtain object[key] for every property of the object.

    0 讨论(0)
提交回复
热议问题