Skip to content

Instantly share code, notes, and snippets.

@toddmotto
Created March 5, 2014 16:34
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 toddmotto/9370782 to your computer and use it in GitHub Desktop.
Save toddmotto/9370782 to your computer and use it in GitHub Desktop.
Recursive Object traversal (loops through Object keys and Arrays)
var updateKeys = function (form) {
var objString = Object.prototype.toString;
var traverse = function (obj) {
if (objString.call(obj) === '[object Array]') {
for (var i = 0; i < obj.length; i++) {
console.log(obj[i].type, obj[i].title);
traverse(obj[i]);
}
} else {
for (var key in obj) {
if (objString.call(obj[key]) === '[object Array]') {
traverse(obj[key]);
}
}
}
};
traverse(form);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment