-3

I have a Site ID's Array at present it is displayed as 112 110 109 108 107 105

But i want to display it in Ascending order please help 105 107 108 109 110 112

the typescript is like this

           item.siteIDs = [];
           (this.subscriptionData || []).forEach((subscription, key) => {
            subscription.sites.filter((obj: any) => {
              if (obj.addressId == item.entityId && !item.siteIDs.includes(obj.siteId)) {
                item.siteIDs.push(obj.siteId);
              }
            });

html like this

                      <td class="col-md-1">
                      <div *ngFor="let siteId of item.siteIDs">
                        {{ siteId }}
                      </div>
                    </td>
Sai Ram
  • 41
  • 7

1 Answers1

0

You can create a sort function like below and after you get the site id array , you can call this method on that array .

var siteIds= [112,110,109,108,107,105]
siteIds.sort((a,b) =>a-b);

In your code :

item.siteIDs = [];
           (this.subscriptionData || []).forEach((subscription, key) => {
            subscription.sites.filter((obj: any) => {
              if (obj.addressId == item.entityId && !item.siteIDs.includes(obj.siteId)) {
                item.siteIDs.push(obj.siteId);
              }
            });
item.siteIDs.sort((a,b) => a-b);
Harmandeep Singh Kalsi
  • 3,315
  • 2
  • 14
  • 26