Typically if we just use alert(object) it will be show as "element object". How to print all the content parameters of an object in JavaScript?
You should consider using FireBug for JavaScript debugging. It will let you interactively inspect all of your variables, and even step through functions.
Use dir(object). Or you can always download Firebug for Firefox (really helpful).
You can also use Prototype's Object.inspect() method, which "Returns the debug-oriented string representation of the object".
http://api.prototypejs.org/language/object.html#inspect-class%5Fmethod
If you just want to have a string representation of an object, you could use the JSON.stringify function, using a JSON library.
Aside from using a debugger, you can also access all elements of an object using a foreach loop. The following printObject function should alert() your object showing all properties and respective values.
function printObject(o) {
var out = '';
for (var p in o) {
out += p + ': ' + o[p] + '\n';
}
alert(out);
}
// now test it:
var myObject = {'something': 1, 'other thing': 2};
printObject(myObject);
Using a DOM inspection tool is preferable because it allows you to dig under the properties that are objects themselves. Firefox has FireBug but all other major browsers (IE, Chrome, Safari) also have debugging tools built-in that you should check.
Internet Explorer 8 has developer tools which is similar to Firebug for Firefox. Opera has Opera DragonFly, and Google Chrome also has something called Developer Tools (Shift+Ctrl+J).
Here is more a more detailed answer to debug JavaScript in IE6-8: http://stackoverflow.com/questions/780059/using-the-ie8-developer-tools-to-debug-earlier-ie-versions/801547#801547
If you are using Firefox, alert(object.toSource()) should suffice for simple debugging purposes.
You can give your objects their own toString methods in their prototypes.