unique values in array javascript
// 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 myArray = ['a', 1, 'a', 2, '1'];
const unique = [...new Set(myArray)]; // ['a', 1, 2, '1']let uniqueItems = [...new Set(items)]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 cors in angular
- what is react mounting
- iframe loader jquery
- javascript index of min value in array
- how to use the map method in javascript
- js how to see console day tomorrow
- strict equality
- bootstrap validator password and confirm password
- javascript charcode
- git remote url change
- loopback ilike
- set class name javascript
- skip part of for each javascript
- how to copy to clipboard in p5.js
- loops javascript
- Material-ui add comment icon
- array fill
- add variable numerically in javascript
- initialize javascript array variable
- encodeuricomponent js
- Object as a Function
- npm image to LM hash
- check if file exists javascript
- javascript indexof with condition