// You can find 6 methods to remove duplicated elements in js array // here on this website: // https://www.geeksforgeeks.org/how-to-remove-duplicate-elements-from-javascript-array/// how to remove duplicates from array in javascript // 1. filter() let num = [1, 2, 3, 3, 4, 4, 5, 5, 6]; let filtered = num.filter((a, b) => num.indexOf(a) === b) console.log(filtered); // Result: [ 1, 2, 3, 4, 5, 6 ] // 2. Set() const removeDuplicates = (arr) => [...new Set(arr)]; console.log(removeDuplicates([1, 2, 3, 3, 4, 4, 5, 5, 6])); // Result: [ 1, 2, 3, 4, 5, 6 ]const myArray = [2,5,6,2,2,4,5,3,3]; const uniqueArray = [...new Set(myArray)]; console.log(uniqueArray);// for TypeScript and JavaScript const initialArray = ['a', 'a', 'b',] finalArray = Array.from(new Set(initialArray)); // a, buniqueArray = a.filter(function(item, pos) { return a.indexOf(item) == pos; }) var myArr = [1, 2, 2, 2, 3]; var mySet = new Set(myArr); myArr = [...mySet]; console.log(myArr); // 1, 2, 3unique = [...new Set(arr)]; // where arr contains duplicate elementsuniqueArray = a.filter(function(item, pos) { return a.indexOf(item) == pos; }) function onlyUnique(value, index, self) { return self.indexOf(value) === index; } // usage example: var a = ['a', 1, 'a', 2, '1']; var unique = a.filter(onlyUnique); console.log(unique); // ['a', 1, 2, '1']function removeDuplicates(arr) { const map = new Map(); const result = []; for (const item of arr) { if (!map.has(item)) { map.set(item, true); result.push(item); } } return result; } const array = [1, 2, 3, 3, 4, 4, 5]; const uniqueArray = removeDuplicates(array); console.log(uniqueArray); // Output: [1, 2, 3, 4, 5][...new Set(['1','1','2','2','3','3'])] //this will return a new array with the unique primitive values //I guess doing this with objects will require implementing equality method.