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


#1

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?


#2

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


#3

This is the line causing the error


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

#4

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);


#5

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


#6

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