I have a simple case of pushing unique values into array. It looks like this:
this.items = [];
add(item) {
if(this.items.indexOf(item) > -1) {
so not sure if this answers your question but the indexOf the items you are adding keep returning -1. Not to familiar with js but it appears the items do that because they are not in the array yet. I made a jsfiddle of a little modified code for you.
this.items = [];
add(1);
add(2);
add(3);
document.write("added items to array");
document.write("
");
function add(item) {
//document.write(this.items.indexOf(item));
if(this.items.indexOf(item) <= -1) {
this.items.push(item);
//document.write("Hello World!");
}
}
document.write("array is : " + this.items);
https://jsfiddle.net/jmpalmisano/Lnommkbw/2/