I need the most efficient way to enumerate the own properties of an object in Javascript. I'm of course aware of the for...in pattern, but according to my tests, it is really a performance gotcha in some scenarios and I would like to work it around somehow.
To be clear, I mean the following basic snippet.
for (var key in myObject) { if (!myObject.hasOwnProperty(key)) continue; ... } I've been thinking about some kind of caching but that's not trivial and also would not allow to catch the properties real-time.
Any suggestions or hints are appreciated.
UPDATE
Turned out based on my small performance test that in a modern browser Object.keys can have huge advantage over other techniques.