const array = [
{
name: 'Jonh',
age: 32
}, {
name: 'James',
age: 33
}, {
name: 'Jacob',
age: 33
}
];
const key = 'age';
const values = new Set();
const filtredArray = array.filter(item => {
const value = item[key];
if (!values.has(value)) {
values.add(value);
return true;
}
return false;
});
ar = [{id: 2},{id: 23},{id: 21},{id: 244},{id: 21},{id: 2},{id: 22},{id: 23}]
const uniqIds = new Set(ar.map(a => a.id));
[...uniqIds]
.map(id => ar.find(a => id === a.id))
.map(el => <Component data={el} />)