Skip to main content
  1. About
  2. For Teams
Asked
Viewed 68k times
12

With $(this).data("events"); returning [object Object], I need to see what's actually going on in 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: (Output) --

Name: click, Value: [object Object] | 

--

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

0

4 Answers 4

19

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

Ctrl+Shift+J gets you to the console in Chrome.

Sign up to request clarification or add additional context in comments.

Comments

16

You can use .toSource() to turn JavaScript objects into a string representation that you can view without a nice error console like in Firebug or Chrome Dev. Tools:

alert($(this).data("events").toSource());

3 Comments

I saw you had toString() in there before... Which was actually a better solution, since that will work on most browsers, where as toSource() will not work in IE.
I almost removed my answer because I can't explain the difference between toString() and toSource(). If anyone knows it'd be nice to have them chime in.
From what I understand, toSource() will convert the object into JSON formatting. W3C: "The toSource() method represents the source code of an object." (w3schools.com/jsref/jsref_toSource_date.asp) Seems like the JSON output is really the key here.
5

If you can't use console.log then alert( $(this).data("events").toSource() ) can also be used.

Comments

3

Print content of object you can use

console.log(obj_str);

you can see the result in console like below.

Object {description: "test"} 

For open console press F12 in chrome browser, you will found console tab in debug mode.

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.