javascript find unique values in array of objects
const myArray = [1,2,3,1,5,8,1,2,9,4];
const unique = [...new Set(myArray)]; // [1, 2, 3, 5, 8, 9, 4]
const myString = ["a","b","c","a","d","b"];
const uniqueString = [...new Set(myString)]; //["a", "b", "c", "d"]const myArray = ['a', 1, 'a', 2, '1'];
const unique = [...new Set(myArray)]; // ['a', 1, 2, '1']//ES6
let array = [
{ "name": "Joe", "age": 17 },
{ "name": "Bob", "age": 17 },
{ "name": "Carl", "age": 35 }
];
array.map(item => item.age)
.filter((value, index, self) => self.indexOf(value) === index)
> [17, 35]const unique = [...new Set(array.map(item => item.age))];var flags = [], output = [], l = array.length, i;
for( i=0; i<l; i++) {
if( flags[array[i].age]) continue;
flags[array[i].age] = true;
output.push(array[i].age);
}
Also in JavaScript:
- javascript continue
- javascript read json file
- How to Set focus to first text input in a bootstrap modal after shown
- Aspect Ratio height react
- javascript yield
- javascript string replace
- javascript string single or double quotes
- npm ERR! 503 Service Unavailable: npm@latest
- To set the text of button using Jquery
- set node process production
- javascript string concatenation
- toggle element javascript
- javascript date now
- how to connect react to backend
- how to get all elements with same class in javascript
- create a slider
- how to check is the key of a localstorage is emopty
- vue store access state in actions
- how to add json data to xmlhttprequest
- js remove item array
- set img src using javascript
- box shadow javascript style change
- dom ready js
- how to define connection string in appsettings.json