| Reference | Downloads | Github

Solving `.filter() is not a function`

URL of experiment:

Description of the problem:
I’m trying to execute something like this bit of code in order to get rid of duplicate responses:

const filtResp = respString.filter((item, index) => {
    return respString.indexOf(item) === index;

But I get the following error message:

The code snippet works outside Pavlovia (i.e. JS Bin). I’ve had the same issue in Pavlovia with .split() and find it very strange as these are quite common methods. That one was fixed when I did .toString().split() though. I’m sure I’m making a mistake somewhere and I would really like to locate it.

Thank you!


Hi @johannenedergaard, I am able to use the filter method, so perhaps the issue is that you are not filtering an array? You can test this using:


If respString is an array, you will see true printed in the console.

Thank you, @dvbridges! You’re right, it wasn’t an array - when I made it into an array, it worked perfectly.