Skip to content

Instantly share code, notes, and snippets.

@appsparkler
Last active September 25, 2018 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsparkler/4f554042b39051b7fce57fa59e66a675 to your computer and use it in GitHub Desktop.
Save appsparkler/4f554042b39051b7fce57fa59e66a675 to your computer and use it in GitHub Desktop.
function isObject(x) {
return Object.prototype.toString.call(x) === '[object Object]';
};
function getObjPath(obj, pathArray, busArray) {
pathArray = pathArray ? pathArray : [];
if (isObject(obj)) {
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (isObject(obj[key])) {
busArray = busArray ? busArray : [];
busArray.push(key);
getObjPath(obj[key], pathArray, busArray);
} else {
if (busArray) {
pathArray.push(busArray.concat([key]));
} else {
pathArray.push([key]);
}
}
}
}
}
return pathArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment