1if(this.items.indexOf(item) === -1) {
2 this.items.push(item);
3 console.log(this.items);
4}
5
1var array = ['test1','test2'];
2var item = 'test2';
3
4if(array.indexOf(item) === -1) {
5 array.push(item);
6}
7// array = ["test1", "test2"]
8
9if(array.indexOf(item) !== -1) {
10 array.push(item);
11}
12// array = ["test1", "test2", "test2"]
1var newItem = "NEW_ITEM_TO_ARRAY";
2var array = ["OLD_ITEM_1", "OLD_ITEM_2"];
3
4array.indexOf(newItem) === -1 ? array.push(newItem) : console.log("This item already exists");
5
6console.log(array)