I am struggling with sorting a list of objects by a string property. The property values are in the format D1, D2 ... D10 ... DXX, always starting with a D followed by a number. However, when I attempt to sort the array using the following code snippet, it does not sort in the expected ascending order:
this.list = v.sort((a, b) => a.property.localeCompare(b.property));
The current result of the sorting looks like this:
Index | Property value |
---|---|
0 | D10 |
1 | D11 |
2 | D3 |
3 | D5 |
... | ... |
I want the sorting results to look like this instead:
Index | Property value |
---|---|
0 | D3 |
1 | D5 |
2 | D10 |
3 | D11 |
... | ... |