0

I have this object with key / value pairs and I'm not able to figure out how to access the keys and values to console.log

[ { ETHBTC: '฿0.05864000', USD: '$391.36', ETHUSDT: '391.30' } ]

I've tried several ways to iterate and am not able to figure out.

J K
  • 1
  • 2
  • this is an array, are you accessing its index before accessing the key/value pairs? – metaldino21 Apr 09 '18 at 20:55
  • Does https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json help? Please show the code you have tried. – str Apr 09 '18 at 20:57
  • Please show us your attempts. There are many, many questions on Stack Overflow about this, including the aforementioned https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json – Heretic Monkey Apr 09 '18 at 20:58
  • I had tried this to print Promise.all([promise1]).then(function(_addField) { Object.keys(_addField).forEach(function(prop) { console.log(prop) console.log(_addField[prop]) }); – J K Apr 09 '18 at 21:14
  • and i get output of { ETHBTC: '฿0.05857600', USD: '$391.99', ETHUSDT: '391.53' } Do I need to then loop again over this to pull out key / values – J K Apr 09 '18 at 21:18
  • I was able to figure this out Promise.all([promise1]).then(function(_addField) { Object.keys(_addField).forEach(function(prop) { Object.keys(_addField[prop]).forEach(function(key) { console.log(key) console.log(_addField[prop][key]) }); Thanks for the links, helped me understand. – J K Apr 09 '18 at 21:27

0 Answers0