I've been working with data in JavaScript, and so far I've been able to do everything I needed on my own. However, I've hit a roadblock.
Explaining the structure of my data is tricky, so let's create a schema for it. Here's what I have:
obj: {[key: string]: {name: string, type: string}[]} =
{
"animals": [
{name: "Louis", type: "dog"},
{name: "John", type: "cat"},
{name: "Jordan", type: "dog"}
],
"cars" : [
{name: "alpha", type: "ferrari"},
{name: "beta", type: "ferrari"},
{name: "charlie", type: "mercedes"}
]
}
My goal is to group each object by type within the list. It should look like this:
obj: {[key: string]: {[key: string]: {name: string, type: string}[]}} =
{
"animals": {
"dog": [
{name: "Louis", type: "dog"},
{name: "Jordan", type: "dog"}
],
"cat": [
{name: "John", type: "cat"}
]
},
"cars" : {
"ferrari": [
{name: "alpha", type: "ferrari"},
{name: "beta", type: "ferrari"}
],
"mercedes": [
{name: "charlie", type: "mercedes"}
]
}
}
Any suggestions on how to accomplish this?