const arr = [1,3,5];
const arrWithObj = [
{id: 1,name: 'test', age: 25},
{id: 2,name: 'test', age: 26},
{id: 3,name: 'test', age: 26},
{id: 4,name: 'test', age: 26},
{id: 5,name: 'test', age: 26},
{id: 6,name: 'test', age: 27},
{id: 7,name: 'test', age: 27},
]
const result = [];
for (const n of arrWithObj) {
if (!arr.includes(n.id)) {
result.push(n);
}
}
const result = arrWithObj.filter(function(n) {
return !this.has(n.id);
}, new Set(arr));
const result = (function get(i, n = arrWithObj[i]) {
return n
? [].concat(~arr.indexOf(n.id) ? [] : n, get(-~i))
: [];
})(0);
const result = Object.values(arr.reduce(
(acc, n) => (delete acc[n], acc),
Object.fromEntries(arrWithObj.map(n => [ n.id, n ]))
));
const result = Array.from(arr.reduce(
(acc, n) => (acc.delete(n), acc),
new Map(arrWithObj.map(n => [ n.id, n ]))
).values());
let filtered = arrWithObj.filter(x => !arr.includes(x.id));