1) There's no other way to enumerate properties than using for..in
(that is until ES5 Object.keys
is implemented). Perhaps if you stated your original problem, someone could suggest a way to optimize.
2) I find it hard to believe that the actual enumeration is taking more than whatever you do with the properties in the loop body.
3) You didn't specify what platform you're developing for. The answer would probably depend on it, and the available language features depend on it too. E.g. in SpiderMonkey (Firefox JS interpreter) you could use for each(var x in arr)
(docs) if you actually need the values, not the keys. It's faster than for (var i in arr) { var x = arr[i]; ... }
.
4) You probably just didn't include it in your snippet, but a faster way to do a for..in
iteration is to make sure the variables you use in the loop are declared in the function with the loop, i.e.:
//slower
for (property in object) { /* do stuff */ }
//faster
for (var property in object) { /* do stuff */ }
5) Related to (4): while trying to optimize a Firefox extension I once noticed that extracting a tight loop into a separate function improved its performance (link). (Obviously, it doesn't mean you should always do that!)