I want to know if there is it is possible to split up an object into multiple objects. I have an array of objects that has another array in it and I was wondering if it is possible to split those objects for each object in the inner array. Something like:
obj1 = [{
a: 1,
b: [{c: 2},{d: 3}],
e: 4
}]
to
obj2 =[
{
a: 1,
b: [{c: 2}],
e: 4
},
{
a: 1,
b: [{d: 3}],
e: 4
}
]
The object is always in this form, whether it has one object or hundreds. While some objects may have more fields in them, there is only one field with an array. Currently, I am mapping across the original array and then mapping again inside the b array to get to each object in there. However, I do not know where to go from there as the return object from that map would just be the original array. I do not know how to split the b array and map it with the original one. I thought of {...orig, b: map()} but I don't think it will work with every object
aandb? Also, can there be more than one element in your source array?bif it has more than one element