手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >用nodejs实现PHP的print_r函数代码
用nodejs实现PHP的print_r函数代码
摘要:复制代码代码如下: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);

【用nodejs实现PHP的print_r函数代码】相关文章:

js实现文本框选中的方法

javascript实现简单的进度条

探索angularjs+requirejs全面实现按需加载的套路

js+cookies实现悬浮购物车的方法

使用RequireJS优化JavaScript引用代码的方法

jQuery实现的多屏图像图层切换效果实例

原生js实现的贪吃蛇网页版游戏完整实例

简单的防盗链功能代码(iframe)

一个表格收缩展开的函数

nodejs修复ipa处理过的png图片

精品推荐
分类导航