I have an API that returns an array of objects(objects represent individual attributes) with individual keys. Objects can have different types and if the object is type 8 or 9 it means it's a multiselect. Multiselect objects look like this:
{
...
type:8
key: attribute6
multiselect_txt: Apple$Carrot$Plum
multiselect_id: 34$13$21
...
}
This would mean that on multiselect the user picked an Apple(id: 34), a Carrot(id: 13) and a Plum(id: 21). So, the text order aligns with the id order and the user picks are seperated by a dollar('$') sign.
My question is, how can I from an array of objects like this:
[
{
key: attribute1
type: 8
multiselect_txt: Apple$Carrot$Plum
multiselect_id: 34$13$21
},
{
key: attribute2
type: 8
multiselect_txt: Coke$Juice
multiselect_id: 11$26
}
]
make an array like this:
[{
attribute1: [{
name: 'Apple'
id: 34
}, {
name: 'Carrot'
id: 13
}, {
name: 'Plum'
id: 21
}],
}, {
attribute2: [{
name: 'Coke'
id: 11
}, {
name: 'Juice'
id: 26
}]
}]