Posted By

Butscharoni on 11/23/07


Tagged

essential


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

heinz1959
korzhik
shockway


print_r for js


 / Published in: JavaScript
 

URL: http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html

  1. function dump(arr,level) {
  2. var dumped_text = "";
  3. if(!level) level = 0;
  4. //The padding given at the beginning of the line.
  5. var level_padding = "";
  6. for(var j=0;j<level+1;j++) level_padding += " ";
  7. if(typeof(arr) == 'object') { //Array/Hashes/Objects
  8. for(var item in arr) {
  9. var value = arr[item];
  10. if(typeof(value) == 'object') { //If it is an array,
  11. dumped_text += level_padding + "'" + item + "' ...\n";
  12. dumped_text += dump(value,level+1);
  13. } else {
  14. dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  15. }
  16. }
  17. } else { //Stings/Chars/Numbers etc.
  18. dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
  19. }
  20. return dumped_text;
  21. };

Report this snippet  

You need to login to post a comment.