Display object contents - JS / jQuery

When $(this).data("events"); [object Object] returns, I need to see what is really going on there. I found this:

 var Finder = ""; $.each($(this).data("events"), function(i, n){ Finder += "Name: " + i + ", Value: " + n + " | "; }); 

However, n still returns [object Object] :

EDIT: (Exit) -

 Name: click, Value: [object Object] | 

-

Is there an efficient way to show everything inside this sucker, sort of like print_r in PHP?

+8
javascript jquery object
source share
4 answers

console.log($(this).data("events")) in Chrome (or other browsers) will allow you to drill an object.

Ctrl + Shift + J will bring you to the console in Chrome.

+15
source share

You can use .toSource() to turn JavaScript objects into a string representation that can be viewed without a good error console, such as Firebug or Chrome Dev. Tools:

 alert($(this).data("events").toSource()); 
+12
source share

If you cannot use console.log , then you can also use alert( $(this).data("events").toSource() ) .

+3
source share

Print the contents of an object that you can use

 console.log(obj_str); 

You can see the result in the console as below.

 Object {description: "test"} 

For an open console, press F12 in the Chrome browser, you will find the console tab in debug mode.

+1
source share

All Articles