javascript pushing item to list without duplication code example
Example 1: javascript remove duplicate in two arrays
array1 = array1.filter(function(val) {
return array2.indexOf(val) == -1;
});
// Or, with the availability of ES6:
array1 = array1.filter(val => !array2.includes(val));
Example 2: javascript dedupe array
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
let x = (names) => names.filter((v,i) => names.indexOf(v) === i)
x(names); // 'John', 'Paul', 'George', 'Ringo'