I am trying to remove duplicate entries in my array of objects where the infoPageId occurs more than once.
Now the logic worked when I used static data but since calling my API the array is empty when console logging.
The array of objects is pretty large therefore I thought wrapping my call in a promise would fix the issue, ensuring the array is fully loaded before tasks are performed on it.
Yet I still produce an empty array after the removal of duplicates. The array is populated after this function is carried out getBuyingGuides.
JSON DATA CALLED FROM SERVER:
this.infos = [ 
    {
        InfoPageId: 8, 
        DepartmentId: 1, 
        Name: "Pitched Roof Window Buying Guide", 
        Url: "buying-guide-pitched", 
        Html: "<div class="background-grey" style="position: rela…. </p></div></div></div></div></div></div>"
    },
    {
        InfoPageId: 8, 
        DepartmentId: 1, 
        Name: "Pitched Roof Window Buying Guide", 
        Url: "buying-guide-pitched", 
        Html: "<div class="background-grey" style="position: rela…. </p></div></div></div></div></div></div>"
    },
    {
        InfoPageId: 8, 
        DepartmentId: 1, 
        Name: "Pitched Roof Window Buying Guide", 
        Url: "buying-guide-pitched", 
        Html: "<div class="background-grey" style="position: rela…. </p></div></div></div></div></div></div>"
    },
    {
        InfoPageId: 8, 
        DepartmentId: 1, 
        Name: "Pitched Roof Window Buying Guide", 
        Url: "buying-guide-pitched", 
        Html: "<div class="background-grey" style="position: rela…. </p></div></div></div></div></div></div>"
    },
    ...
    {
        InfoPageId: 8, 
        DepartmentId: 1, 
        Name: "Pitched Roof Window Buying Guide", 
        Url: "buying-guide-pitched", 
        Html: "<div class="background-grey" style="position: rela…. </p></div></div></div></div></div></div>"
    },
    {
        InfoPageId: 8, 
        DepartmentId: 1, 
        Name: "Pitched Roof Window Buying Guide", 
        Url: "buying-guide-pitched", 
        Html: "<div class="background-grey" style="position: rela…. </p></div></div></div></div></div></div>"
    }
]
infos: Array<{InfoPageId: number, DepartmentId: number, Name: string, Url: string, Html: string, Title: string, Keywords: string, Description: string, InfoTypeId: number, DateCreated: Date, DateUpdated: Date, Hidden: boolean, AMPhtml: string, UseAmp: boolean, UseAmpVideo: boolean, UseCarousel: boolean, TradeOnly: boolean, TagId: number}> = [];
ngOnInit(): void {
    this.getBuyingGuides().then(() => this.getUniqueValues(this.infos));
}
getBuyingGuides() {
    this.infos = [];
    var promise = new Promise((resolve, reject) => {
        setTimeout(() => {
            this._SharedService.getAll().subscribe((data: any[]) => {
                data.forEach(e => {
                    if(e.InfoTypeId = 12) {
                        this.infos.push(
                            new infoPage(
                                e.InfoPageId, 
                                e.DepartmentId, 
                                e.Name, 
                                e.Url, 
                                e.Html,
                                e.Title, 
                                e.Keywords,
                                e.Description, 
                                e.InfoTypeId, 
                                e.DateCreated, 
                                e.DateUpdated, 
                                e.Hidden, 
                                e.AMPhtml,
                                e.UseAmp, 
                                e.UseAmpVideo, 
                                e.UseCarousel,
                                e.TradeOnly,
                                e.TagId
                            )
                        );
                    }     
                })
          })
          resolve();
        }, 
        1000
      );
      });
     return promise;
}
getUniqueValues(infos: Array<infoPage>) {      
    const out = infos.reduce(
        (acc, cur) => acc.some(
            x => x.InfoPageId === cur.InfoPageId
            ) ? acc : acc.concat(cur), 
        []
    )
    console.log(out)
}
 
     
     
    