const myArray = [1,2,3,1,5,8,1,2,9,4]; const unique = [...new Set(myArray)]; // [1, 2, 3, 5, 8, 9, 4] const myString = ["a","b","c","a","d","b"]; const uniqueString = [...new Set(myString)]; //["a", "b", "c", "d"]
Array.from(arrayLike object);
// Use to remove duplicate elements from the array const numbers = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5] //spreading numbers of the object into an array using the new operator console.log([...new Set(numbers)]) // [2, 3, 4, 5, 6, 7, 32]
var arr = [55, 44, 65]; var set = new Set(arr);
return Array.from(new Set(this.posts.map(e => e.category)))