Skip to content

Instantly share code, notes, and snippets.

@sisodiakaran
Created September 11, 2015 21:51
Show Gist options
  • Save sisodiakaran/be5b25a26dd80332cbe3 to your computer and use it in GitHub Desktop.
Save sisodiakaran/be5b25a26dd80332cbe3 to your computer and use it in GitHub Desktop.
JS Recursive Function
var home = {
room_1: {
tube: 5,
fan: 6,
lamp: {
one: 7,
two: {
two_1: 8,
tow_two: 9
}
}
}
};
var a = [];
var recursive_setup = function(start) {
var b = [];
if (typeof start !== "object") {
a.push(start);
} else {
for (i in start) {
b.push(recursive_setup(start[i]));
}
}
return a;
};
console.log(recursive_setup(home));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment