for (var key in object) in CoffeeScript? [duplicate]

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.


Solution 1:

for key of object

Try it in js2coffee

Solution 2:

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