Created
May 2, 2013 20:08
-
-
Save akluth/5505005 to your computer and use it in GitHub Desktop.
CoffeeScript: JSON-Objects, Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Considering an JSON object like this one: | |
# | |
# { | |
# "store": { | |
# "foo": { | |
# "value":"bar" | |
# } | |
# }, | |
# "anotherstore": { | |
# "wat":{ | |
# "value":"dat" | |
# } | |
# } | |
# } | |
# | |
# To get the "root" elements (e.g. 'store', 'anotherstore') use this construct: | |
for name of obj | |
console.log name | |
# To get the objects (e.g. 'foo', 'wat') of those elements | |
for i of obj | |
console.log "%j", obj[i] | |
# It took a quite long time to get me there... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment