I need sort array with Bustype and index
What I have
[
{ BusType: "SATA", index: 1, Id: "SATA.1" },
{ BusType: "SATA", index: 10, Id: "SATA.10" },
{ BusType: "IDE", index: 1, Id: "IDE.1" },
{ BusType: "IDE", index: 2, Id: "IDE.2" },
{ BusType: "IDE", index: 10, Id: "IDE.10" },
]
Expected ouput:
[
{ BusType: "IDE", index: 1, Id: "IDE.1" },
{ BusType: "IDE", index: 2, Id: "IDE.2" },
{ BusType: "IDE", index: 10, Id: "IDE.10" },
{ BusType: "SATA", index: 1, Id: "SATA.1" },
{ BusType: "SATA", index: 10, Id: "SATA.10" }
]
I tried this:
arr.sort((a, b) => a.Id.localeCompare(b.Id))
but got this :
[
{ BusType: "IDE", index: 1, Id: "IDE.1" },
{ BusType: "IDE", index: 10, Id: "IDE.10" },
{ BusType: "IDE", index: 2, Id: "IDE.2" },
{ BusType: "SATA", index: 1, Id: "SATA.1" },
{ BusType: "SATA", index: 10, Id: "SATA.10" }
]
Sorting like alphabet.. 1 10 100 2 20 3
how to sort in right derection?