imtiaz imtiaz - 11 months ago 49
Javascript Question

how to get the output of object in javascript

when I add some object in editor & when I go to the browser to see the output, it only shows [object object] .Can any one tell me how to see the output of object in browsers

enter code here

// alert('Hello world ');

var contacts= new Array();

var add = function(firstName,lastName,phoneNumber,email)

this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber =phoneNumber; = email;

contacts[contacts.length] = new add("imtiaz","ahmed","01794705874","");

contacts[contacts.length] = new add("johny","bob","998978788","");

document.write( "</br>" + contacts);

Answer Source

Lets say if you have an object like this.

 var Somebody = {
 name: "John Smith",
 age: 120};

To print it in the browser you can use JSON like this.

alert(JSON.stringify(Somebody, null, 3));