Created
July 31, 2017 14:08
-
-
Save dongho-jung/e6ae718392bdc02aa314ed5dc69d61b5 to your computer and use it in GitHub Desktop.
this script dismantle an object recursively
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
<script> | |
function clickme(){ | |
var display = document.getElementById('display'); | |
var sample = {a:1 , b:2 , c:3 , d:{q:1,w:2,e:3,f:{z:'hmm', x:'oh', c:'exe'}}}; | |
var i; | |
var allElement = 'window\r\n'; | |
allElement += inspect(window,1); | |
display.innerText = allElement; | |
} | |
function inspect(x, depth){ | |
var i, n; | |
var elements = ''; | |
if(depth > 3) | |
return ''; | |
for(i in x){ | |
for(n=0;n<depth;n++) | |
elements += ' '; | |
if(x[i] == '') | |
elements += '└' + i + ': blank\r\n'; | |
else | |
elements += '└' + i + ': ' + x[i] + '\r\n'; | |
if(typeof x[i] === 'object') | |
elements += inspect(x[i], depth+1); | |
} | |
return elements; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment