源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

用nodejs实现PHP的print_r函数代码

  • 时间:2021-06-27 00:52 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:用nodejs实现PHP的print_r函数代码
[u]复制代码[/u] 代码如下:
function ergodic(obj,indentation){   var indent = "  " + indentation;   if(obj.constructor == Array || obj.constructor == Object){     for(var p in obj){       if(obj[p].constructor == Array|| obj[p].constructor == Object){         console.log(indent + "["+p+"] => "+typeof(obj)+"");         console.log(indent + "{");         ergodic(obj[p], indent);         console.log(indent + "}");       } else if (obj[p].constructor == String) {         console.log(indent + "["+p+"] => '"+obj[p]+"'");       } else {         console.log(indent + "["+p+"] => "+obj[p]+"");       }     }   } } function print_r(obj) {   console.log("{")   ergodic(obj, "");   console.log("}") } var stu = {'name':'Alan','grade':{'Chinese':120,'math':130,'competition':{'NOI':'First prize'}}}; print_r(stu);
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部