1

I have two classes like this

export interface ClosureSummary {
    Domain:             string;
    DomainCode:         string;
    FundingDomain:      string;
    FundingDomainCode:  string;
    ProjectManager:     string;
    ProjectManagerCode: string;
    PipelineOwner:      string;
    PipelineOwnerCode:  string;
    ProjectCode:        string;
    ProjectName:        string;
    ProjectType:        string;
    LifeCycle:          string;
    Framework:          string;
    ProjectEndDate:     Date;
    Financials:         number;
    Forecast:           number;
    Risk:               number;
    AR2:                number;
    ClosureCertificate: number;
    ClosureType:        string;
    Milestone:          number;
    Artefacts:          number;
    Issue:              number;
    PEPIC:              number;
}

export interface MultiselectItem{
{
    id:      string;
    name:    string;
}

Here the second smaller interface is just for dropdown controls for which the data being filtered from the main class without any duplicate.

So I did a function like this

closureDomains:MultiselectItem[]=[];
clSummary:ClosureSummary[]=[];
//here getting data into clsummary
..
this.closureDomains = res.map((x) =>{ return { id:x.DomainCode,name:x.Domain};}).filter(function (elem, index, self) {
            return index === self.indexOf(elem)
          });

So the closureDomains array now contains DomainCode and DomainName correctly, but with duplicates.

I think my filter part not working correctly.

Please share your thoughts.

Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132
  • Does this answer your question? [How to remove all duplicates from an array of objects?](https://stackoverflow.com/questions/2218999/how-to-remove-all-duplicates-from-an-array-of-objects) – Adnan Sharif Oct 28 '21 at 02:55

0 Answers0