I am wondering if there is a way to dynamically add objects to an array of objects based on a value? For example, I have an array of objects:
[
{category:A, num:5},
{category:B, num:2}
]
I want to create another array of objects where objects would be the same, but repeated based on the value of num (so 5 times for category A and 2 times for category B) :
[
{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 have tried map, forEach, for loop, but nothing worked. I am quite new to javascript, how some one could help!
javawithjavascript?