Last active
June 24, 2018 07:54
-
-
Save blackmiaool/3084adee1971ff3404444b4d79a5077d to your computer and use it in GitHub Desktop.
getCircularKeys
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
function getCircularKeys(obj,opt={left:100}){ | |
if(!obj||typeof obj!=='object'){ | |
return ; | |
} | |
let keys=Object.keys(obj); | |
function appendKeys(keys){ | |
opt.left-=keys.length; | |
if(opt.left<=0){ | |
return true; | |
} | |
} | |
if(appendKeys(keys)){ | |
return keys; | |
} | |
for(const key in obj){ | |
const propertiesKeys=getCircularKeys(obj[key],opt); | |
keys=[...keys,...propertiesKeys] | |
if(appendKeys(propertiesKeys,opt)){ | |
return keys; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment