Skip to content

Instantly share code, notes, and snippets.

@creaux
Created November 24, 2014 19:45
Show Gist options
  • Save creaux/c8bc6fff937b9007a0ef to your computer and use it in GitHub Desktop.
Save creaux/c8bc6fff937b9007a0ef to your computer and use it in GitHub Desktop.
<!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>
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