1var array = [1, 2, 2, 3, 3, 4, 5, 6, 2, 3, 7, 8, 5, 22, 1, 2, 511, 12, 50, 22];
2
3console.log([...new Set(
4  array.filter((value, index, self) => self.indexOf(value) !== index))]
5);1let arr =["a","b","c"];
2// ES6 way
3const duplicate = [...arr];
4
5// older method
6const duplicate = Array.from(arr);1// JavaScript - finds if there is duplicate in an array. 
2// Returns True or False.
3
4const isThereADuplicate = function(arrayOfNumbers) {
5    // Create an empty associative array or hash. 
6    // This is preferred,
7    let counts = {};
8    // // but this also works. Comment in below and comment out above if you want to try.
9    // let counts = [];
10
11    for(var i = 0; i <= arrayOfNumbers.length; i++) {
12        // As the arrayOfNumbers is being iterated through,
13        // the counts hash is being populated.
14        // Each value in the array becomes a key in the hash. 
15        // The value assignment of 1, is there to complete the hash structure.
16        // Once the key exists, meaning there is a duplicate, return true.
17        // If there are no duplicates, the if block completes and returns false.
18        if(counts[arrayOfNumbers[i]] === undefined) {
19            counts[arrayOfNumbers[i]] = 1;
20        } else {
21            return true;
22        }
23    }
24    return false;
25}1[1, 1, 2, 2, 3].filter((element, index, array) => array.indexOf(element) !== index) // [1, 2]