Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question JavaScript equivalent of PHP print_r()

    If there a JavaScript equivalent of PHP's print_r() or vardump()? This would be very handy for debugging.
    Last edited by bauhsoj; 08-20-2005 at 12:54 AM.

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function var_dump(obj) {
    	if(typeof obj == "object") {
    		return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
    	} else {
    		return "Type: "+typeof(obj)+"\nValue: "+obj;
    	}
    }
    
    /* usage */
    window.onload = function() {
    	var myString = "hello world";
    	alert(var_dump(myString));
    	
    	var myInteger = 10;
    	alert(var_dump(myInteger));
    	
    	var myArray = new Array(1,2,3);
    	alert(var_dump(myArray));
    	
    	alert(var_dump(window));
    }
    </script>
    </head>
    
    <body>
    </body>
    </html>
    Just an idea, hope it helps.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    470
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Much thanks! Very close to what I was looking for.

  • #4
    New to the CF scene
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    you can also use Firebug [www.getFirebug.com]

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #6
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    var_dump

    I have created a JavaScript code that is very similar to PHP's var_dump:
    http://rubsphp.blogspot.com/2011/03/...avascript.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •