javascript get distinct values from array
// usage example:
var myArray = ['a', 1, 'a', 2, '1'];
var unique = myArray.filter((v, i, a) => a.indexOf(v) === i);
// unique is ['a', 1, 2, '1']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']
Also in JavaScript:
- adding to array js
- how to create response time router node js
- disable js in chrome dev tools
- how sent data to dilaog angular material
- Modify the function increment by adding default parameters so that it will add 1 to number if value is not specified.
- delete session javascript
- js check if array
- pass params react js
- JQuery UI Saving Sortable List
- shorthand if in javascript with return
- react fun tion
- moment for react
- how to check if an element exists in an array of objects js
- javascript detect mobile device
- ng g c
- reverse proxy using expressjs
- array of images javascript
- for in javascript
- js detect all images errors
- react js download file
- input set variable angular
- cordova load javascript without cache
- discord js check if person banned
- jquery table row calculation