Is there a way to iterate over properties in an object without using a for in loop?
According to Nicholas C. Zakas, it takes 8x longer for a for in loop to iterate over an object than a for loop, but i cant find a way to iterate over the properties of an object without changing their names to something like 1, 2, 3 etc. witch isn’t ideal.
Speed is the main concern for me.
You can have another array that holds your keys. Something like this:
However, that’s ugly. Performance in this kind of case will never be your bottleneck, you should rather prefer readability. The code up there can be done this way:
Which is just way cleaner and more readable. (
for..incould also be used, it was just for the sake of the example)