This article describes how to use nodejs to implement the print_r Function Code of PHP. For more information, see
The Code is as follows:
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': {'China': 120, 'Math': 130, 'computing': {'noi ': 'First Prize '}}};
Print_r (stu );