-1

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

here is the code

// alert('Hello world ');
var contacts = new Array();
var add = function(firstName, lastName, phoneNumber, email) {
  this.firstName = firstName;
  this.lastName = lastName;
  this.phoneNumber = phoneNumber;
  this.email = email;
};
contacts[contacts.length] = new add("imtiaz", "ahmed", "01794705874", "imtiaz@gmail.com");
contacts[contacts.length] = new add("johny", "bob", "998978788", "bob@gmail.com");
document.write("</br>" + contacts);
droidev
  • 7,352
  • 11
  • 62
  • 94
imtiaz
  • 3
  • 2

3 Answers3

0

Try console.log(yourObject);. It will display on your browser's console.

XeNo13GrIn
  • 122
  • 5
  • yeah it shows in browsers console but not in the main place and I have provided the code please see – imtiaz Oct 11 '16 at 07:07
0

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));
Celaro
  • 196
  • 1
  • 7
  • 19
  • Celaro it worked but why did u add null and 3 ? It also worked without them – imtiaz Oct 11 '16 at 07:18
  • Like it states here [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) stringily takes 3 arguments, the object, a optional function to filter the properties of the object, and the number of space between each output – Celaro Oct 11 '16 at 07:28
0
alert(JSON.stringify(contacts));
imtiaz
  • 3
  • 2