用nodejs实现PHP的print_r函数代码_Javascript教程-查字典教程网
用nodejs实现PHP的print_r函数代码
用nodejs实现PHP的print_r函数代码
发布时间:2016-12-30 来源:查字典编辑
摘要:复制代码代码如下:functionergodic(obj,indentation){varindent=""+indentation;if(...

复制代码 代码如下:

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

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类