What's the fastest way to iterate over an object's properties in Javascript?

后端 未结 8 1702
旧巷少年郎
旧巷少年郎 2020-12-13 00:25

I know that I can iterate over an object\'s properties like this:

for (property in object)
{
    // do stuff
}

I also know that the fastest

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 00:55

    Object.keys() coupled with the traditonal for loop to iterate over the keys, and lookup for the values out performs all other techniques. Here is a comprehensive performance comparison.

    https://gists.cwidanage.com/2018/06/how-to-iterate-over-object-entries-in.html

提交回复
热议问题