Created
March 5, 2014 16:34
-
-
Save toddmotto/9370782 to your computer and use it in GitHub Desktop.
Recursive Object traversal (loops through Object keys and Arrays)
This file contains 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
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