i want print the content of a javascript object in a string format like when we alert a variable in javascript same way i want print the object in formatted way
Well, Firefox and other advanced browsers have Object.toSource() method which prints objects as JSON and function(){}
.
That's enough for most debugging purposes, I guess.
If you want to print the object for debugging purposes, I suggest instead installing Firebug for Firefox and using the code:
console.log(obj)
var output = '';
for (property in object) {
output += property + ': ' + object[property]+'; ';
}
alert(output);
RE: Triptych
If you want to print the object for debugging purposes, I suggest instead installing Firebug for Firefox and using the code:
console.log(obj)
Remember to enable the Console tab in Firebug.
Doesn't help when the object appears fine in FF and not so much in IE8. What are some options for dumping an object's contents while running it in IE8?
If you want to use alert, to print your object, you can do this:
alert("myObject is " + myObject.toSource());
It should print each property and its corresponding value in string format.