php print_r怎么换行,用js写了一个类似php的print_r输出换行功能

代码如下:

var my={

str:”,

deep:0,

block:’ ‘,

get_pre:function(n)

{

pre=”;

for(i=0;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’)//如果是对象

{

pre=this.get_pre(this.deep);

this.str+=pre+k+’=>OBJECT{n’;

this.deep++;//开始递归,深度+1

this.show_obj(obj[k]);

pre = this.get_pre(this.deep);

this.deep–;//递归结束一个 深度-1

this.str+=pre+’}n’;

}

else if(typeof(obj[k])==’object’ && typeof(obj[k].length)!=’undefined’)//如果是数组

{

pre=this.get_pre(this.deep);

this.str+=pre+k+’=>ARRAY[n’;

this.deep++;//同对象

this.show_obj(obj[k]);

pre = this.get_pre(this.deep);

this.deep–;//同对象

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’}}}});

//–>

chrome 可以用 console.log

ie的话,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值