Posted in NodeJs onMarch 14, 2014
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函数代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@