I have data coming from a react-select custom component that looks like this:-
[
[
{label: “name1”, value: “name1”, Group_Number: “Group1”}
{label: “name2”, value: “name2", Group_Number: “Group1”}
]
[
{label: “name3”, value: “name3”, Group_Number: “Group2”}
{label: “name4”, value: “name4”, Group_Number: “Group2”}
]
]
The outer array length is dynamic and so is the inner array length, based on values that the user selects. How do I transform this in this format.
[
{
Group_Number: “Group1”,
Players: [
“name1”,
“name2”
]
},
{
Group_Number: "Group 2",
Players: [
“name3”,
“Name4”
]
}
]
tried all techniques like foreach, map, reduce etc etc...Not able to crack it
[
[
{label: “name1”, value: “name1”, Group_Number: “Group1”}
{label: “name2”, value: “name2", Group_Number: “Group1”}
]
[
{label: “name3”, value: “name3”, Group_Number: “Group2”}
{label: “name4”, value: “name4”, Group_Number: “Group2”}
]
]
The outer array length is dynamic and so is the inner array length, based on values that the user selects. How do I transform this in this format.
[
{
Group_Number: “Group1”,
Players: [
“name1”,
“name2”
]
},
{
Group_Number: "Group 2",
Players: [
“name3”,
“Name4”
]
}
]
tried all techniques like foreach, map, reduce etc etc...Not able to crack it