Remove Duplicate values after *ngFor

Hi all,
This is my scenario,i want remove duplicate values from ion-options.

<ion-select [(ngModel)]="deliveryDate" placeholder="Date" item-start>
			<ion-label>Choose Date</ion-label>
			<ion-option  *ngFor="let order of pending_orders " value="{{order?.delivery_date}}">{{order?.delivery_date}}</ion-option>
</ion-select>

Thanks in advance :wink:

Hello,

is there a necessary reason why you want do that in the template?
Imho, keep your template as dumb as possible and use in template an array that only keeps need values.

Best regards, anna.liebt

1 Like

Hi@anna_liebt
Thanks for the reply,i want to remove the duplicate values from json array
i think i do it in template is becase

[
{deliverydate:"19 monday"},
{deliverydate:"18monday"},
{deliverydate:"19 monday"}
]

I want to avoid the duplication of deliverydate in ion options,19 monday needs to show once.
can you help me on this?

Hello,

little bit symplified, but something like that.

Best regards, anna-liebt

Hi@anna_liebt
Thanks again,But my API response is not just an array,Json array of objects and delivery date is one of my key,Any way let me try this

Hi@anna_liebt
Thats not working .Still the value is duplicated.I passed a json array of object to removeDuplicates function.I thinks this works only in case of array operation.Will not incase of array of objects.

  removeDuplicates(arr){
       console.log(arr);
    let unique_array = []
    for(let i = 0;i < arr.length; i++){
        if(unique_array.indexOf(arr[i]) == -1){
            unique_array.push(arr[i])
        }
    }
    return unique_array
}

Hi.
Why you complicate your life ?
Try to use lodash library there is a function called : uniqBy to remove duplicate values

Hi@yajuve
:joy::joy::joy:
Anyway thaks for the reply.Can i remove the duplicate value from json array of objects?
Could you please make an example?

Yes you can. please search " lodash uniqBy " there is an example in the doc its very easy.

Okey Thanks @yajuve
Let me try that.