Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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']
Comment

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']

Comment

PREVIOUS NEXT
Code Example
Javascript :: select a random element from from items array 
Javascript :: javascript countdown 10 seconds 
Javascript :: saving json file python 
Javascript :: array.foreach 
Javascript :: checking a point is in polygon 
Javascript :: js test if i am in iframe 
Javascript :: input change event in javascript 
Javascript :: javascript make new date from hour 
Javascript :: props to react router link 
Javascript :: netlify refresh page not found 
Javascript :: javascript interview preparation 
Javascript :: document selector query change value 
Javascript :: remove space from string javascript 
Javascript :: remove null and undefined from array 
Javascript :: javascript array remove empty strings 
Javascript :: js check if object is empty 
Javascript :: invalid geojson object leaflet 
Javascript :: what is sus imposter 
Javascript :: compress string javascript 
Javascript :: fetchData from json file 
Javascript :: write json file nodejs 
Javascript :: axios configure base url 
Javascript :: jQuery UI Sortable, then write order into a database 
Javascript :: how to validate age above 18 in javascript 
Javascript :: javascript for loop starting from end 
Javascript :: js cypress div text 
Javascript :: google sign up react npm 
Javascript :: split a message 
Javascript :: javascript console output 
Javascript :: immediately invoked function in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =