for (var key in object) in CoffeeScript?

JavascriptCoffeescript

Javascript Problem Overview


How can I use for (var key in object) in CoffeeScript? It compiles to...

for (_i = 0, _len = object.length; _i < _len; _i++) {
    key = object[_i];

...but I just want to iterate though an object.

Javascript Solutions


Solution 1 - Javascript

for key of object

Try it in js2coffee

Solution 2 - Javascript

of keyword:

for key, value of obj

or to make sure you're only checking properties on this object (and not the prototype chain):

for own key, value of obj

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfancyView Question on Stackoverflow
Solution 1 - JavascriptRaynosView Answer on Stackoverflow
Solution 2 - JavascriptNoneView Answer on Stackoverflow