Make array elements unique in JavaScript

The easiest way to remove duplicates from array is probably to use Set() method as it is presented in the example below.

array = [...new Set(array)];

Example:

Remove duplicated values from JavaScript array.

<script>
    myArray = ['dog', 'dog', 'cat'];
    myArray = [...new Set(myArray)];

    console.log(myArray);
</script>

Output (console):

['dog', 'cat']