用nodejs实现PHP的print

2019-12-23,,

复制代码 代码如下:
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);

您可能感兴趣的文章:

  • nodejs对express中next函数的一些理解
  • NodeJS中利用Promise来封装异步函数
  • nodejs文件操作模块FS(File System)常用函数简明总结
  • nodejs中函数的调用实例详解

《用nodejs实现PHP的print.doc》

下载本文的Word格式文档,以方便收藏与打印。