I have a collection of items as follows:
[{
"id": "123",
"title": "Article 1",
"evaluationLevel": {
"levelName":A
},
"category": ["Category 1", "Category 2", "Category 3"]
},
{
"id": "234",
"title": "Article 2",
"evaluationLevel": {
"levelName":B
},
"category": ["Category 2", "Category 4"]
},
{
"id": "567",
"title": "Article 3",
"evaluationLevel": {
"levelName":C
},
"category": ["Category 1"]
}]
I'm looking to organize this data in the following way:
{
"Category 1": [
["1", "Article 1", A],
["2", "Article 3", C]
],
"Category 2": [
["3", "Article 1", A],
["4", "Article 2", B]
],
"Category 3": [
["5", "Article 1", A]
],
"Category 4": [
["6", "Article 2", C]
]
}
Is there a more efficient method for sorting and grouping objects like this using JavaScript? I came across a helpful discussion on How to group an array of objects by key. However, my case requires grouping based on values within the category object.