How to examine objects in Node.js?

1

I assign a variable to an object, I do console.log with it with intention to find out and examine what is inside the object, but when I start the code in console ( CLI ) ( PowerShell ), this console.log simply returns the following: [object] [Object]

How can I proceed to see the object, as for example happens in javascript on the frontend side, when we do console.log and run inside the browser?

Thank you.

    
asked by PacoTiger 22.05.2017 в 14:50
source

1 answer

0

You can use a for in:

var objeto = {
 nombre: 'Juan',
 apellido: 'López',
 direccion: {
  calle: 'Sol',
  numero: '1',
  colonia: 'Galaxia'
 }
}

for (var prop in objeto){
  console.log('Propiedad: ' + prop + ' - Valor: ' + objeto[prop])
}

for (var prop in objeto.direccion){
  console.log('Propiedad: ' + prop + ' - Valor: ' + objeto.direccion[prop])
}

As you can see, I do two for in because there is another object inside the object.

I hope you serve

    
answered by 24.05.2017 / 22:21
source