Answers for "filter an array of objects and match its key with values inside another array"

1

filter array of objects by another array of objects

const array = [
    { id: 1, name: 'a1', sub: { id: 6, name: 'a1 sub' } },
    { id: 2, name: 'a2', sub: null },
    { id: 3, name: 'a3', sub: { id: 8, name: 'a3 sub' } },
    { id: 4, name: 'a4', sub: null },
    { id: 5, name: 'a5', sub: { id: 10, name: 'a5 sub' } },
];

const anotherArray = [
    { id: 1, name: 'a1', sub: { id: 6, name: 'a1 sub' } },
    { id: 2, name: 'a2', sub: null },
    { id: 5, name: 'a5', sub: { id: 10, name: 'a5 sub' } },
];

const r = array.filter((elem) => !anotherArray.find(({ id }) => elem.id === id) && elem.sub);

console.log(r);
Posted by: Guest on May-24-2021
3

javascript filter array of objects by array

var arr = [1,2,3,4],
    brr = [2,4],
    res = arr.filter(f => !brr.includes(f));
console.log(res);
Posted by: Guest on July-06-2020
0

filter an array of objects and match its key with values inside another array

const arr = [1, 2, 3, 4]
const brr = [2, 4]
const res = arr.filter((f) => !brr.includes(f))
console.log(res)
Posted by: Guest on November-13-2020

Code answers related to "filter an array of objects and match its key with values inside another array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language