I have the below array of objects. Now I need to filter and create 3 separate array of objects based on the key value.
"data": [
{
"BaseId": 1,
"BaseDesc": "18 BHC Baseline",
"StressId": 5,
"StressDesc": "Desc 1",
"bopId": 8,
"bopDesc": "BOP Desc 1",
},
{
"BaseId": 1,
"BaseDesc": "Baseline 2",
"StressId": 2,
"StressDesc": "Desc 12",
"bopId": 8,
"bopDesc": "BOP Desc 2"
},
{
"BaseId": 2,
"BaseDesc": "Baseline 3",
"StressId": 7,
"StressDesc": "Desc 3",
"bopId": 10,
"bopDesc": "BOP Desc 3"
}
]
Now I need to filter this and create 3 separate array of object such that:
1. BaseData Array Obj
"baseData": [
{
"BaseId": 1,
"BaseDesc": "18 BHC Baseline"
},
{
"BaseId": 1,
"BaseDesc": "Baseline 2"
},
{
"BaseId": 2,
"BaseDesc": "Baseline 3"
}
]
Stress Array Obj:
"data": [ { "StressId": 5, "StressDesc": "Desc 1" }, { "StressId": 2, "StressDesc": "Desc 12" }, { "StressId": 7, "StressDesc": "Desc 3" } ]
And similarly 3rd object for bop data. So if my actual array contains "base*" in the keys, then I need to filter and add to bop Array and same logic goes for other two array of objects.
Can someone please guide me how to achieve this.