包括未按预期过滤 Angular 5

Includes not filtering as expected in Angular 5

我正在尝试使用 include 进行过滤以显示来自建筑物地址的状态。例如,我只想显示华盛顿一次,即使那里有十座建筑物

for (let i=0; i<=this.professional.hospital.length; i++) {
        if(this.professional.hospital[i].address && this.professional.hospital[i].address.length > 0) {
            if (this.states.includes(this.professional.hospital[i].address[0].state) === false) {
                this.states.push({label: this.professional.hospital[i].address[0].state,
                    value: this.professional.hospital[i].address[0].state
                });
            }
        }
    }

这通常是我的做法,但它正在添加状态,即使它在数组中 大家有什么想法

for (let i=0; i<this.professional.hospital.length; i++) {
        if(this.professional.hospital[i].address && this.professional.hospital[i].address.length > 0) {
            if (!this.states.find(x => x.value == this.professional.hospital[i].address[0].state)) {
                this.states.push({label: this.professional.hospital[i].address[0].state,
                    value: this.professional.hospital[i].address[0].state,
                });
            }
        }
    }

我明白了。如果有人被困在上面,这就是方法