1var arr = [55, 44, 65,1,2,3,3,34,5];
2var unique = [...new Set(arr)]
3
4//just var unique = new Set(arr) wont be an array
1const myArray = ['a', 1, 'a', 2, '1'];
2const unique = [...new Set(myArray)]; // ['a', 1, 2, '1']
1function toUniqueArray(a){
2 var newArr = [];
3 for (var i = 0; i < a.length; i++) {
4 if (newArr.indexOf(a[i]) === -1) {
5 newArr.push(a[i]);
6 }
7 }
8 return newArr;
9}
10var colors = ["red","red","green","green","green"];
11var colorsUnique=toUniqueArray(colors); // ["red","green"]
1var array3 = [1, 2, 4, 6, 1, 4, 9, 10, 2, 8];
2function findUniqueElements_3(array) {
3
4 for (let i = 0; i < array.length; i++) {
5 for (let j = i + 1; j < array.length; j++) {
6 if (array[i] == array[j]) {
7 array.splice(j, 1)
8 }
9
10 }
11 }
12 console.log(`from third way : ${array}`);
13}
14
15findUniqueElements_3(array3)