8

How do I iterate through the keys in an object to display the key and values associated with it? Say the hash is the following:

hash =
a: 'b'
c: 'd'
e: 'f'

2 Answers2

18
for key, value of hash
    console.log "#{key} = #{value}"
James M
  • 18,506
  • 3
  • 48
  • 56
6

Try this:

for k, v of hash
    console.log('%s %s', k, v)