×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Black Light
Added: Mar 13, 2013 11:51 AM
Views: 15
Tags: no tags
  1. alert(print_r(your array));  //call it like this
  2.  
  3. function print_r(arr,level) {
  4. var dumped_text = "";
  5. if(!level) level = 0;
  6.  
  7. //The padding given at the beginning of the line.
  8. var level_padding = "";
  9. for(var j=0;j<level+1;j++) level_padding += "    ";
  10.  
  11. if(typeof(arr) == 'object') { //Array/Hashes/Objects
  12.     for(var item in arr) {
  13.         var value = arr[item];
  14.  
  15.         if(typeof(value) == 'object') { //If it is an array,
  16.             dumped_text += level_padding + "'" + item + "' ...\n";
  17.             dumped_text += print_r(value,level+1);
  18.         } else {
  19.             dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  20.         }
  21.     }
  22. } else { //Stings/Chars/Numbers etc.
  23.     dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
  24. }
  25. return dumped_text;
  26. }