我有這個在我的.ts文件:如何從數組中刪除重複的名稱?
search(event) {
this.autocompletedata.filter((entry) => {
console.log('entryyyy',entry);
if (this.showFilter == 1) {
this.results = entry['items'].filter(a => a['item'] ? a['item'].startsWith(event.query) : false);
}
else if (this.showFilter == 2) {
this.results = entry['items'].filter(a => a['service'] ? a['service'].startsWith(event.query) : false);
}
else if (this.showFilter == 3){
this.results = entry['items'].filter(a => a['phoneNum'] ? a['phoneNum'].startsWith(event.query) : false);
}
});
}
問題是,我得到的數據,但我得到的重複數據。任何建議如何從數組中刪除重複的數據?
這是我完整的自動完成代碼。
這是我的項目的結構:
現在,在過去的if語句我有結果,他們建議,因爲在陣列我有多次相同數量的我建議得到該號碼,我不想要那個 - 我只想要顯示一個。
使用過濾器代替的forEach並根據病情 –
我有數組中的數組 – uzhas
然後使用過濾器過濾器內返回true或false 。並保持你的結局! –