Anybody knows if it is possible to get a
javascript for/in loop
from coffeescript?
Actually would like to write the js function
function logobject(o) {
for (p in o)
console.log(p + "=" + o[p])
}
in coffeescript.
This might be a bit confusing for CoffeeScript newbies, but the for..in loop is used to iterate over arrays, while the for..of loop is used to iterate over objects.
logobject = (o) ->
console.log key + "=" + value for key, value of o
Also, to restrict this to own properties of the object (skips inherited properties via hasOwnProperty()), the "own" keyword can be added:
for own key, value of o
coffee-scriptprogrammer, but shouldn't it work just as it is?:)