JS multi-conditional recursive classification problem?

1. I have a set of data, and I want to group them according to a set of conditions, roughly as follows:

[{id: 1, name: "Sean", age: 22, sex: "Male"},
{id: 2, name: "Sean", age: 12, sex: "Male"},
{id: 3, name: "Tom", age: 21, sex: "Male"},
{id: 4, name: "John", age: 25, sex: "Male"}]

I want to classify according to a set of conditions. for example, ["name","age","sex"] currently has only three, but requires a wireless loop, for example, I get an array object when I finish dividing it for the first time.

{Sean:[
        {id: 1, name: "Sean", age: 22, sex: "Male"},
        {id: 2, name: "Sean", age: 12, sex: "Male"}
      ],
 John:[
        {id: 4, name: "John", age: 25, sex: "Male"} 
      ],
  Tom:[
         {id: 3, name: "Tom", age: 21, sex: "Male"}
      ]
}

then I"m reclassifying according to this result. Get the data classified according to age, and then I reclassify by gender according to the data obtained by age. It"s a super disgusting cycle. I already have the method of classification. But how to write this recursion. Ask for expert advice. I really can"t figure it out.

Mar.05,2021

it's best not to stare at your data, but to focus on the "requirements" you want to achieve. Guess you are doing classification screening, if, as you said, to go on like this "disgusting cycle", you can not stand it, the user can bear it?


Why should we classify them in advance, put the original data there, and just take out the parts we need when we need them?

let result = data.filter(item => {
  return item.name === 'Sean' && item.sex === 'Male'
})
Menu