filter array with unique objects javascript
const array =
[
{ "name": "Joe", "age": 17 },
{ "name": "Bob", "age": 17 },
{ "name": "Carl", "age": 35 }
]
const key = 'age';
const arrayUniqueByKey = [...new Map(array.map(item =>
[item[key], item])).values()];
console.log(arrayUniqueByKey);
/*OUTPUT
[
{ "name": "Bob", "age": 17 },
{ "name": "Carl", "age": 35 }
]
*/
// Note: this will pick the last duplicated item in the list.//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))];
Also in JavaScript:
- react html symbol code
- show html file on nodejs code
- jquery visible
- javscript async await explained
- how to send get request to external server using node
- angular formData print values
- jquery check checkbox
- datepicker in react
- how to use fetch() javascript
- how to change the staticness of a object in matter.js
- react native init project
- read and save excel with react
- rebuild android react native
- create a form and submit it dynamically jquery
- all fields entered jquery enable submit button
- nodejs promise then example
- react hook form validate email
- javascript are arrays equal
- create dynamic fields in react
- convert string to array javascript
- clone object in js
- angularjs left xx characters
- converting binary to text js
- reactjs app change port