3 ms·
JavaScript's for-in construct is not the same as iterating through all elements in the array as it will enumerate over all of the object's properties (see here:
by henryl 15y ago
JavaScript's for-in construct is not the same as iterating through all elements in the array as it will enumerate over all of the object's properties (see here: http://stackoverflow.com/questions/500504/javascript-for-in-with-arrays http://stackoverflow.com/questions/500504/javascript-for-in-...)
The other "complexities" in the compiled JavaScript are there for perf reasons (not accessing the "length" properties in the condition portion of the for loop, for example).
Your comment underlies why some users find CoffeeScript useful in dealing with some of the idiosyncrasies and performance minutiae associated with JavaScript.
- gavinlynch 15y agoRight, for..in is not the same as iterating through all elements in an array. Understood. But it works excellent in the example the OP created and in my follow-up example. And I agree that accessing the length property in the conditional is not ideal. I guess it comes down to this for me: I don't feel that Javascript has an unduly burdensome list of common idiosyncrasies to justify developing in a 'different language'/syntax that compiles into javascript and changing my development workflow to reap said questionably useful benefits. Perhaps I am simply not the intended audience.