Created
September 17, 2012 09:55
-
-
Save arestov/3736506 to your computer and use it in GitHub Desktop.
iterateObjectDeeply, no recurstion
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 iterateObjectDeeply = function(obj, fn) { | |
var full_tree_array = [obj]; | |
while (full_tree_array.length) { | |
var cur = full_tree_array.shift(); | |
for (var a in cur){ | |
fn(cur, a); | |
if (cur[a] && typeof cur[a] == 'object'){ | |
full_tree_array.push(obj[prop_name]) | |
} | |
} | |
} | |
return obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment