Answers for "how to make elements of array distinct js"

3

javascript get distinct values from array

const categories = ['General', 'Exotic', 'Extreme', 'Extreme', 'General' ,'Water', 'Extreme']
.filter((value, index, categoryArray) => categoryArray.indexOf(value) === index);

This will return an array that has the unique category names
['General', 'Exotic', 'Extreme', 'Water']
Posted by: Guest on April-03-2020
2

js get distinct values from array

var myArray = ['a', 1, 'a', 2, '1'];

let unique = [...new Set(myArray)];

console.log(unique); // unique is ['a', 1, 2, '1']
Posted by: Guest on August-09-2021

Code answers related to "how to make elements of array distinct js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language