This question already has an answer here:
- How can I display a JavaScript object? 35 answers
Typically if we just use alert(object);
it will show as [object Object]
. How to print all the content parameters of an object in JavaScript?
This question already has an answer here:
Typically if we just use alert(object);
it will show as [object Object]
. How to print all the content parameters of an object in JavaScript?
You can give your objects their own toString methods in their prototypes.
Simple function to alert contents of an object or an array .
Call this function with an array or string or an object it alerts the contents.
Function
Usage
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: Using the IE8 'Developer Tools' to debug earlier IE versions
If you just want to have a string representation of an object, you could use the
JSON.stringify
function, using a JSON library.You can use json.js from http://www.json.org/js.html to change json data to string data.
I faced similar problem, The reason for it was i make use of ajax to fetch data. In this case i had made two asynchronous ajax call. In one i just return string msg and show in alert. In second ajax call i fetch arraylist in json format and decode it in js. So my second request use to process first and i was getting alert of object.
So just check. 1. alert should contain string. 2. If u get arrayList or any other Object decode it.
All the best!