I am trying to perform the sorting array inside the object inside the array
here my First Array Object :
firstObj = [{
id: "111",
name: "one",
type: "user"
},
{
id: "222",
name: "two",
type: "user"
},
{
id: "333",
name: "three",
type: "admin"
},
{
id: "444",
name: "four",
type: "user"
},
{
id: "555",
name: "five",
type: "user"
},
{
id: "666",
name: "six",
type: "admin"
}
]
here my Second Array Object :
secondObj = [
{
ids: ['333', '666', '555', '222'],
name: "handlers"
}
]
I am successfully sorting First array using below line.
firstObj.sort((p1,p2) => (p1.id > p2.id) ? -1 : 1);
I need a Second array Object ids array Sort with comparing a firstObj id.
I tried many ways But had no luck. Can Anyone Suggest to me How It's possible?
Expected Output:
secondObj = [
{
ids: ['222', '333', '555', '666'],
name: "handlers"
}
]