I'm currently developing a new application and struggling with grouping data. The data is being pulled from an observable, and I need to group objects by their status and push them into an array. I attempted to use the groupBy() method, but unfortunately, it did not produce the desired results.
Here is a snippet of what I have:
const data = [
{
id: 3424234,
name: "asdfgasdgas",
protocol: 235452345,
status: {
code: "AVAILABLE",
displayName: "Available"
}
},
{
id: 543534,
name: "regertjerg",
protocol: 7745672345,
status: {
code: "AVAILABLE",
displayName: "Available"
}
},
{
id: 96089678,
name: "kluioliudas",
protocol: 7878745,
status: {
code: "INITIALREVIEW",
displayName: "Initial review"
}
}
]
Now, this is how I envision the data grouped:
const result = [
{
code: "AVAILABLE",
displayName: "Available",
items: [
{
id: 3424234,
name: "asdfgasdgas",
protocol: 235452345
},
{
id: 543534,
name: "regertjerg",
protocol: 7745672345
}
]
},
{
code: "INITIALREVIEW",
displayName: "Initial review",
items: [
{
id: 96089678,
name: "kluioliudas",
protocol: 7878745
}
]
}
]
Your assistance in solving this challenge is greatly appreciated!