Last active
September 25, 2018 05:57
-
-
Save appsparkler/4f554042b39051b7fce57fa59e66a675 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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