Hello this is a rather complicated question.
I have an array of objects:
let animals = [
{
"typ": "rats",
"name": "RB 1",
},
{
"typ": "mice",
"name": "MB 1",
},
{
"typ": "rats",
"name": "RB 4",
},
{
"typ": "rats",
"name": "RB 2",
},
{
"typ": "rats",
"name": "RB 3",
},
{
"typ": "mice",
"name": "MB 2",
},
{
"typ": "mice",
"name": "MB 3",
}
this array can have up to a few hundred objects and several other animals too!!!
now i want to sort it so that i have all rats first and then all mice after that...
A second step would be to sort all rats and mice by name like RB 1 , RB2 , RB 3 ....so that i get an array like this
[
{
"typ": "rats",
"name": "RB 1",
},
{
"typ": "rats",
"name": "RB 2",
},
{
"typ": "rats",
"name": "RB 3",
},
{
"typ": "rats",
"name": "RB 4",
},
{
"typ": "mice",
"name": "MB 1",
},
{
"typ": "mice",
"name": "MB 2",
},
{
"typ": "mice",
"name": "MB 3",
}]
I get the initial array from a firestore collection with snapshotChanges() so the objects(documents in the firestore database) all come in in random order
Thanx everybody
edit:
@secan posted a working solution! thanx man