Some help needed please (JavaScript)

Hello everyone. Let’s say for instance, I have a colors object containing several array of colors like this:

const colors = { primaryColors: [‘Red’, ‘Yellow’, ‘Blue’ ], secondaryColors: [‘Green’, ‘Purple’, ‘Orange’], tertiaryColors: [‘Green’, ‘Purple’, ‘Orange’], };

How do I destructure each property of the colors object using a for loop?

Normally without using loops I could do it this way:

const [primaryColors, secondaryColors, tertiary Colors] = Object.keys[color];

But the reason why I want to use a loop to achieve this is cuz I want a situation whereby I don’t know the number of properties the objects has. So instead of destructuring them individually, I want to use a loop.

Hello @Adetunji

what about using 2 dimension array would it help ?

and have a nice day :slight_smile:

You can do so by using nested for loops. A single for loop will not get the job done because you have a lot of arrays in the object. So take your time and learn something about javascript nested for loops and easily implements it.

You can use the “for in loop”
example for(let key in colors) { console.log(key + ": " + colors[key])}