Created
November 24, 2014 19:45
-
-
Save creaux/c8bc6fff937b9007a0ef to your computer and use it in GitHub Desktop.
// source http://jsbin.com/nedupafihe
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var foobar = { | |
"foo": { | |
"whooop" : { | |
"bar" : 123, | |
"elses" : 'trdlo' | |
}, | |
"elses" : 'prdel' | |
} | |
}; | |
function gatherer(needle, stack) { | |
if (stack instanceof Object) { | |
for (var key in stack) { | |
if (key == needle) { | |
console.log(stack[key]); | |
} else { | |
gatherer(needle, stack[key]); | |
} | |
} | |
} | |
} | |
gatherer('elses', foobar); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var foobar = { | |
"foo": { | |
"whooop" : { | |
"bar" : 123, | |
"elses" : 'trdlo' | |
}, | |
"elses" : 'prdel' | |
} | |
}; | |
function gatherer(needle, stack) { | |
if (stack instanceof Object) { | |
for (var key in stack) { | |
if (key == needle) { | |
console.log(stack[key]); | |
} else { | |
gatherer(needle, stack[key]); | |
} | |
} | |
} | |
} | |
gatherer('elses', foobar);</script></body> | |
</html> |
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 foobar = { | |
"foo": { | |
"whooop" : { | |
"bar" : 123, | |
"elses" : 'trdlo' | |
}, | |
"elses" : 'prdel' | |
} | |
}; | |
function gatherer(needle, stack) { | |
if (stack instanceof Object) { | |
for (var key in stack) { | |
if (key == needle) { | |
console.log(stack[key]); | |
} else { | |
gatherer(needle, stack[key]); | |
} | |
} | |
} | |
} | |
gatherer('elses', foobar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment