This is quite simple question, I got a Json like this:
const test = [
{
label: "Group 1",
options: [
{ label: "option 1", value: "value_1" },
{ label: "option 2", value: "value_2" }
]
},
{
label: "Group 1",
opions: [
{ label: "option 3", value: "value_3" },
{ label: "option 4", value: "value_4" }
]
},
{
label: "Group 2",
options: [
{ label: "option 5", value: "value_5" },
{ label: "option 6", value: "value_6" }
]
},
{
label: "Group 3",
options: [
{ label: "option 7", value: "value_7" },
{ label: "option 8", value: "value_8" }
]
},
{
label: "Group 3",
options: [
{ label: "option 9", value: "value_9" },
{ label: "option 10", value: "value_10" }
]
},
];
And I want to group them like this (by the Group label - the format is exactly as described below, I cannot add any other values as I'll use it in the react-select component as options)
const test = [
{
label: "Group 1",
options: [
{ label: "option 1", value: "value_1" },
{ label: "option 2", value: "value_2" },
{ label: "option 3", value: "value_3" },
{ label: "option 4", value: "value_4" }
]
},
{
label: "Group 2",
options: [
{ label: "option 5", value: "value_5" },
{ label: "option 6", value: "value_6" }
]
},
{
label: "Group 3",
options: [
{ label: "option 7", value: "value_7" },
{ label: "option 8", value: "value_8" },
{ label: "option 9", value: "value_9" },
{ label: "option 10", value: "value_10" }
]
},
];
How can I achieve that?
Thanks in advance