dspencer
dspencer

Reputation: 928

How to iterate through JSON hash with coffeescript

I'm new to Coffeescript and I'm having issues resolving an issue. I have a JSON object that is currently stored in a variable. How do I iterate through the keys in the JSON object to display the key name and values associated with it?

if client
  result = JSON.parse client
  $.each result, (k, v) ->
    alert k + " is " + v

Any help would be appreciated.

Upvotes: 18

Views: 18727

Answers (2)

Nicolas Maturana
Nicolas Maturana

Reputation: 21

result = JSON.parse client
     for c in result
        console.log(c.key +"-"+ c.value)

it's work!

Upvotes: 1

zemirco
zemirco

Reputation: 16395

for key, value of result
  console.log "#{key} and #{value}"

more in the docs#loops

Upvotes: 50

Related Questions