Tracing array like print_r


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function print_a( obj, indent ) {
  2. if (indent == null){
  3. indent = "";
  4. }
  5. var out = "";
  6. var start:Boolean = true;
  7. for ( item in obj ) {
  8. if (typeof( obj[item] ) == "object" ){
  9. if(!start){
  10. out += "n"+indent+ "[" + item + "] => Object";
  11. }
  12. else{
  13. out += indent+ "[" + item + "] => Object";
  14. }
  15. start = false;
  16. }
  17. else {
  18. out += indent+"[" + item + "] => " + obj[item]+"";
  19. }
  20. out += print_a( obj[item], indent+" " ) + " ";
  21. }
  22. return out;
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.