I see a couple of issues:
You want taskStateRemove variable to be an array of strings, right? Then it should be defined this way (with square brackets)
var taskStateRemove = ["failed","completed","killed","finished"];
The second issue is with indexOf(). You are using it as searchElement.indexOf(array) but it should be array.indexOf(searchElement). In your code, it should be
if (taskStateRemove.indexOf(task.state) > -1 && ...