Thursday, 8 June 2017

Node.js - console.log does not show items in array but instead shows [Object]

I have a problem with logging out the contents of an array inside an object. The actual object looks like this

   var stuff = { accepted: [ 'item1', 'item2' ],
         rejected: [],
         response: 'Foo',
         envelope: { from: 'The sender', to: ['new item1', 'new item2'] },
         messageId: 'xxxxxxxxxxxxx' } }

The console.log shows the items of the first array fine but the second array is being output as [Object].

 { accepted: [ 'item1', 'item2' ],
             rejected: [],
             response: 'Foo',
             envelope: { from: 'The sender', to: [Object] },
             messageId: 'xxxxxxxxxxxxx' } } 

What is happening here and how can I get the items of the second array to show when I console.log. Thanks for any help!

UPDATE

Sorry, I forgot to add that I am working exclusively in Node.js so it's a server side log that needs to display the object exactly as it's received from a callback.



via mikeym

No comments:

Post a Comment