Skip to content
Advertisement

What’s the cleanest way to turn an object into a list without using a double for loop?

I have an object called ‘times’, that holds another object called ‘20102’, that holds a list of 3 objects. It looks like this:

JavaScript

However, what I want it to look like is this:

JavaScript

I was thinking of doing a double for loop but that’s not efficient. What’s a better way?

Advertisement

Answer

using Object.values() and flat()

JavaScript

If you know there will only be one key

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement