<div class="codetitle"> <span><a style="CURSOR: pointer" data="98386" class="copybut" id="copybut98386" onclick="doCopy('code98386')"><u>コードをコピー</u></a></span> コードは次のとおりです。</div> <div class="codebody" id="code98386"> <br><script type="text/javascript"> <br> <!-- <BR>var my={ <BR>str:'', <BR>deep:0, <BR>block:' ', <BR>get_pre:function(n) <BR> { <BR>pre=''; <BR>for(i=0;i<n;i ) <BR>{ <BR>pre =this.block; <BR>return <BR> }, <BR>show_obj:function(obj) <BR>{ <BR>for(k in obj) <BR>{ <BR>if(typeof(obj[k])!='object' && typeof(obj[ k]) !='array') <BR>{ <BR>pre=this.get_pre(this.deep); <BR>this.str =pre k '=>' obj[k] <br>} <br>else if(typeof(obj[k])=='object' && typeof(obj[k].length)=='unknown')//オブジェクトの場合<br>{ <br>pre=this.get_pre(this.deep); <br>this.str =pre k '=>OBJECT{n'; <br>this.deep ;//再帰を開始します、深さ 1 <br>this.show_obj (obj[k] ); <br>pre = this.get_pre(this.deep); <br>this.deep--;//再帰は深さ -1 で終了します <br>this.str =pre ' }n'; <br>} <br>else if(typeof(obj[k])=='object' && typeof(obj[k].length)!='unknown')//配列の場合<br>{ <br>pre=this.get_pre(this.deep); <br>this.str =pre k '=>ARRAY[n'; <br>this.deep ;//同じオブジェクト<br> .show_obj(obj[k]); <br>pre = this.get_pre(this.deep); <br>this.deep--;//同じオブジェクト<br>this.str =pre ']n'; 🎜>} <br>} <br> return this.str; <br>}, <br>alert_obj:function(obj) <br>{ <br>alert(this.show_obj(obj)) <br>} <br>} <br>my.alert_obj( {a:{b:{c:{d:'hello world'}}}}); <br>//-></script> 🎜><br> <br>chrome OK console.log <br>を使用する場合、つまり、</div>