Skip to content

Instantly share code, notes, and snippets.

@gsharp
Created December 2, 2009 10:58
Show Gist options
  • Save gsharp/247133 to your computer and use it in GitHub Desktop.
Save gsharp/247133 to your computer and use it in GitHub Desktop.
objectrecurse.js
var p = function(msg) {
console.log(msg); // because I frequently mis-spell consele.lgo (no it doesn't work in ie..silly)
};
doIt = function(aObj) {
for (k in aObj) {
var v = aObj[k]; // assign value to v
typeof v != 'string' ? p(k + ": ") || doIt(v) : p(k + ": " + v); // if not string recurse else output k,v
}
}
var someObj = {
"foo" : "bar",
"right" : "wrong",
"Colors" : {
"cool" : "blue",
"hot" : "red"
}
}
doIt(someObj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment