Is there a way to dynamically add objects to an array of objects based on a value? Let's say we have the following array of objects:
[
{category:A, num:5},
{category:B, num:2}
]
I would like to create another array where objects are repeated based on the 'num' value (5 times for category A and 2 times for category B), like this:
[
{category:A, num:5, repeated:1},
{category:A, num:5, repeated:2},
{category:A, num:5, repeated:3},
{category:A, num:5, repeated:4},
{category:A, num:5, repeated:5},
{category:B, num:2, repeated:1},
{category:B, num:2, repeated:2}
]
I've attempted using map, forEach, and for loops but haven't had success. I'm new to JavaScript and would appreciate any help or guidance!