var my_array = [5, 4, 7, 8, 9, 2, 7, 5, 4, 8, 7];
// First Method
unique_array = my_array.filter((item, index, array) => array.indexOf(item) === index);
console.log("Unique Array is : " + unique_array);
// Second Method
var another_uni_arr = [...new Set(my_array)];
console.log("Another Unique Array is : " + another_uni_arr);
In the first method, we are using Array.filter() method and checking if the item already exists in the array or not by using .indexOf() method.
0 Comments