const filtered = arrWithObj.filter(n => !arr.includes(n.id));
// или
const filtered = arrWithObj.filter(function(n) {
return !this.has(n.id);
}, new Set(arr));
// или
const filtered = Array.from(arr.reduce(
(acc, n) => (acc.delete(n), acc),
new Map(arrWithObj.map(n => [ n.id, n ]))
).values());
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} />)
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;
});