0

I need to print all datas in an object in a for loop but I don't know how to access to their index.

For example I have an object like this (this is an example ,but the real one is very big)

a = { name : richard ,last_name : stallman };

I can do this :

cnosole.log(a.name);
cnosole.log(a.last_name);

But the object is too big.How can I do this?

Elyas74
  • 548
  • 1
  • 5
  • 18

2 Answers2

2

Our you could do it like this:

a = { name : 'richard' ,last_name : 'stallman' };

for( key in a){
    console.log(a[key]);
}
Hank Lapidez
  • 1,857
  • 18
  • 23
0

You can convert an object to a string with JSON.stringify.

console.log(JSON.stringify(a));

should print something like:

{"name": "richard", "last_name": "stallman"}
user253751
  • 57,427
  • 7
  • 48
  • 90