Skip to content

Instantly share code, notes, and snippets.

@commanda
Created July 27, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commanda/48b611bd8f4fd1e5708c7ac2aa9d6822 to your computer and use it in GitHub Desktop.
Save commanda/48b611bd8f4fd1e5708c7ac2aa9d6822 to your computer and use it in GitHub Desktop.
traverse a json-ish structure in javascript
function traverse(object, block)
{
for(var i in object)
{
block(typeof(object[i]) !== "object", i, object[i]);
if(object[i] !== null && typeof(object[i]) !== "string")
{
traverse(object[i], block);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment