Solution 1 :

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);

Problem :

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>

Comments

Comment posted by Sai Ram

No sir, can you modify the typescript code i wrote and provide me a solution please

Comment posted by gorak

@SaiRam You can either build a pipe for that or just

Comment posted by Sai Ram

Cannot read property ‘sort’ of undefined

Comment posted by Sai Ram

Hi Haemandeep i got this error

Comment posted by Harmandeep Singh Kalsi

It is type : it should be item.siteIDs instead of item.sideIDs .I updated the answer

Comment posted by Harmandeep Singh Kalsi

Good to know that

Comment posted by stackoverflow.com/questions/65810945/…

Hi @Harmandeep singh can you help me to resolve this issue please

By