Is there a way to properly sort a JSON array in Angular? Here is the array for reference:
{"title":"DEASDFS","Id":11},
{"title":"AASDBSC","Id":2},
{"title":"JDADKL","Id":6},
{"title":"MDASDNO","Id":3},
{"title":"GHFASDI","Id":15},
{"title":"HASDFAI","Id":1},
{"title":"ASDHFI","Id":9},
The desired order of the Id's should be as follows:
15,6,1,11,9,2,3
<div *ngFor="let field of fieldsData;let i=index;">
<div class="form-inline assigned_text-box" [ngSwitch]="field.Id">
<div class="col-md-2" *ngSwitchCase="15">
<label>One</label>
</div>
<div class="col-md-2" *ngSwitchCase="6">
<label>Two</label>
</div>
<div class="col-md-2" *ngSwitchCase="1">
<label>Three</label>
</div>
<div class="col-md-2" *ngSwitchCase="11">
<label>Four</label>
</div>
<div class="col-md-2" *ngSwitchCase="9">
<label>Five</label>
</div>
<div class="col-md-2" *ngSwitchCase="2">
<label>Six</label>
</div>
<div class="col-md-2" *ngSwitchCase="3">
<label>Seven</label>
</div>
</div>
</div>
However, currently when using the ngSwitch
condition, the items are displayed in the order they appear in the JSON data: 11,2,6,3,15,1,9
My goal is to display them in this particular order instead: 15,6,1,11,9,2,3. How can I achieve this custom sorting of the array?