Skip to content

Instantly share code, notes, and snippets.

@sms-system
Last active December 16, 2015 05:29
Show Gist options
  • Save sms-system/5384718 to your computer and use it in GitHub Desktop.
Save sms-system/5384718 to your computer and use it in GitHub Desktop.
Эквивалент print_r() для javascript (http://htmlweb.ru/java/example/print_r.php)
function print_r(arr, level) {
var print_red_text = "";
if(!level) level = 0;
var level_padding = "";
for(var j=0; j<level+1; j++) level_padding += " ";
if(typeof(arr) == 'object') {
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') {
print_red_text += level_padding + "'" + item + "' :\n";
print_red_text += print_r(value,level+1);
}
else
print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
else print_red_text = "===>"+arr+"<===("+typeof(arr)+")";
return print_red_text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment