Break in loop doesn't work

I am using the Firebase and I have the followig code

  getCustomers() { 
    let array = []; 
    this.service.getItems().subscribe(res => {
      for(let customer of res) {
        if(customer['salesman_id'] == this.salesman_id) {
          array.push(customer);
          console.log(array)
        }  
      }
      this.customers = array
    })
  }

in my console I observable this situation

The loop repeat several times, how to resolve its ?

Your thread topic says “break in loop doesn’t work”, but I’m not seeing any “break” in code you have posted, nor under what conditions getCustomers() is being called. You also say “the loop repeat several times” as if that were not desired, but “repeat several times” is what loops do. Your console.log statement looks like it will fire once for each customer in the response that matches the given salesman, so maybe it would help if you could describe what you are expecting or wanting to happen and how it differs from what is happening.

Incidentally, here is how I would write your getCustomers function (and I would move it out of the page and into the service):

allCustomers(): Observable<Customer[]> {
  // renamed from getItems()
}

customersOfSeller(sellerId: string): Observable<Customer[]> {
  return this.allCustomers().pipe(
    map(custs => custs.filter(cust => cust['salesman_id'] === sellerId)));
}