That feels like a lot of work. If you are looping through a plain object the for..in loop could help.
for..in
This works.
function format_response(response) { let result = []; for(let crypto in response) { let data = { name: crypto }; for(let currency in response[crypto]) { data.currency = currency; data.value = response[crypto][currency]; } result.push(data); } return result; } const data = {"BTC":{"USD":18188.04},"ETH":{"USD":557.07}}; format_response(data);
Thanks, interesting! I'm sure there is more than one solution for this type of problem. I just wanted to share with something new I learned.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That feels like a lot of work. If you are looping through a plain object the
for..in
loop could help.This works.
Thanks, interesting!
I'm sure there is more than one solution for this type of problem. I just wanted to share with something new I learned.