Uncaught (in promise): TypeError: this.indexOf is not a function

I keep getting this error when trying to use filter, i also get the same error if i use .includes . I’m getting this error in the console of the browser. Is this an ionic problem or an angular problem?

Your code is malformed somewhere. If you post the line causing the error, someone can probably help you out.

This is the line causing the error


         this.filteredBeers = this.filteredBeers.filter(function(e){return this.indexOf(e)<0;},favouriteDrinkIds);

You don’t want to be typing function inside an Ionic app.

Instead, utilize the “fat arrows” syntax () =>.

In your case:
this.filteredBeers = this.filteredBeers.filter((e) => {return this.indexOf(e)<0;},favouriteDrinkIds);

Ah ok, still getting my head round coding in typescript/ ionic , is there anything else i need to watch out for?

I know also get the error Property ‘indexOf’ does not exist on type ‘MyListPage’ , so slightly different this time…