Copy codeThe Code is as follows:
<Script type = "text/javascript">
<! --
Var my = {
Str :'',
Deep: 0,
Block :'',
Get_pre: function (n)
{
Pre = '';
For (I = 0; I <n; I ++)
{
Pre + = this. block;
}
Return pre;
},
Show_obj: function (obj)
{
For (k in obj)
{
If (typeof (obj [k])! = 'Object' & typeof (obj [k])! = 'Array ')
{
Pre = this. get_pre (this. deep );
This. str + = pre + k + '=>' + obj [k] + '\ n ';
}
Else if (typeof (obj [k]) = 'object' & typeof (obj [k]. length) = 'undefined') // if it is an object
{
Pre = this. get_pre (this. deep );
This. str + = pre + k + '=> OBJECT {\ n ';
This. deep ++; // start recursion, depth + 1
This. show_obj (obj [k]);
Pre = this. get_pre (this. deep );
This. deep --; // recursively end a depth-1
This. str + = pre + '} \ n ';
}
Else if (typeof (obj [k]) = 'object' & typeof (obj [k]. length )! = 'Undefined') // if it is an array
{
Pre = this. get_pre (this. deep );
This. str + = pre + k + '=> ARRAY [\ n ';
This. deep ++; // same object
This. show_obj (obj [k]);
Pre = this. get_pre (this. deep );
This. deep --; // same object
This. str + = pre + '] \ n ';
}
}
Return this. str;
},
Alert_obj: function (obj)
{
Alert (this. show_obj (obj ))
}
}
My. alert_obj ({a: {B: {c: {d: 'Hello world '}}}});
// -->
</Script>
Chrome can use console. log
For ie,