I have something like this:
items: { _id: number; place: SomeAddressClassDto }[] = [];
sessionItem: { _id: number; place: SomeAddressClassDto };
createAddressList() {
this.service.getWorkingPlaces().subscribe((items) => {
this.items = items;
this.sessionItem = {
place: JSON.parse(sessionStorage.getItem('currentPlace')),
_id: this.items.length,
};
this.items.push(this.sessionItem);
// _.uniqBy(this.items, 'place')
const idx = items.findIndex((item) => this.service.comparePlaces(item.place,
this.service.getCurrentWorkingPlace()));
if (idx !== -1) this.radiobox.option = `${idx}`;
});
}
I am trying to remove any duplicates from 'items' array using the method _uniqBy, but it isn't working. I think it's because for this items._id are always different but items.place could be equal and if are I would like to get rid of this.
Maybe better way is to check is the same items.place is already in that array, but no idea how to do this.
EDIT: To be more specify, items looks like this:
0: place: {name, street, city, etc...}
_id: 0
So it is possible to have very similar object whitch is differnet only by one property in place{}