10
var object = { name: 'Harry', age: '25', sex: 'male'...... n};

This object has 'n' number of properties which I don't know and I would like to print these whole properties.

Andreas
  • 20,797
  • 7
  • 44
  • 55
SAI KRISHNA
  • 159
  • 1
  • 1
  • 11

3 Answers3

20

There are heaps of solutions from a quick Google, a recomended result is; Print content of JavaScript object?

console.log(JSON.stringify(object, null, 4));

The second argument alters the contents of the string before returning it. The third argument specifies how many spaces to use as white space for readability.

Florian Suess
  • 353
  • 3
  • 7
13

You can use the The Object.keys() function to get an array of the properties of the object:

var obj = { name: 'Harry', age: '25', sex: 'male'};
Object.keys(obj).forEach((prop)=> console.log(prop));
Fullstack Guy
  • 15,365
  • 3
  • 24
  • 41
-1

Generally you can do that with:

console.log(object);

Further instructions are in this topic: What is the JavaScript equivalent of var_dump or print_r in PHP?

ilyaki
  • 17
  • 3