1

Here my code and what i tried :

filterPrestationsByServiceSelected(arrayOfServices) {
    console.log(arrayOfServices); // ['Repassage', 'Couture']
    this.filteredPrestationsByService = this.filteredPrestations.filter(item => item.service.name.includes(arrayOfServices.values()));
},

I want to filter all items of this.filteredPrestations where the service name contains values of the arrayOfServices.

Anyone have an idea of what i can do ? Thank's !

5
  • Can you add a example array? Commented Mar 9, 2020 at 11:44
  • ['Repassage', 'Couture', 'Automobile'] Commented Mar 9, 2020 at 11:45
  • 1
    remove the .values at the end. arrayOfServices.values() Commented Mar 9, 2020 at 11:45
  • 1
    this.filteredPrestationsByService = this.filteredPrestations.filter(item => arrayOfServices.includes(item)); ? Commented Mar 9, 2020 at 11:46
  • 1
    Wow ! That's works ! @EugenSunic Thank's ! Commented Mar 9, 2020 at 11:46

3 Answers 3

1

Remove .values() it returns an iterator which you don't need

filterPrestationsByServiceSelected(arrayOfServices) {
    console.log(arrayOfServices); // ['Repassage', 'Couture']
    this.filteredPrestationsByService = this.filteredPrestations.filter(item => item.service.name.includes(arrayOfServices));
}
Sign up to request clarification or add additional context in comments.

Comments

0

You have to compare the items of a list with another. So you would have to have a compare each element of one data structure with another. Since you are comparing arrays you should do that way:

filterPrestationsByServiceSelected(arrayOfServices) {
    console.log(arrayOfServices); // ['Repassage', 'Couture']
    this.filteredPrestationsByService = this.filteredPrestations.filter(item => arrayOfServices.find(e => e === item.service.name))
},

That way you could compare the elements one by one.

Comments

0

Can you try this code. I think this code will work.

filterPrestationsByServiceSelected(arrayOfServices) {
    console.log(arrayOfServices); // ['Repassage', 'Couture']
    this.filteredPrestationsByService = this.filteredPrestations.filter(item => arrayOfServices.includes(item.service.name));
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.