Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
Comment

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)
Comment

PREVIOUS NEXT
Code Example
Javascript :: dropdown search field in react native 
Javascript :: import syntax node 
Javascript :: array javascript django 
Javascript :: pass variable to partial view ejs 
Javascript :: js push array to array 
Javascript :: truncate string in javascript 
Javascript :: nested for loop js 
Javascript :: arry to object using reduce 
Javascript :: trim() javascript 
Javascript :: convert table to excel reactjs 
Javascript :: define a class in javascript 
Javascript :: loop over an array 
Javascript :: puppeteer wait for page loadjavascript 
Javascript :: addeventlistener javascript 
Javascript :: ran ctrl c and npm server is still running 
Javascript :: images not displaying in react 
Javascript :: joi validation enum 
Javascript :: variable used in a function can be used in another function js 
Javascript :: bson to json converter 
Javascript :: javascript regex exact match 
Javascript :: javascript math absolute 
Javascript :: api testing app with websocket 
Javascript :: c# razor for loop javascript 
Javascript :: javascript replace spaces with br 
Javascript :: store with redux-thunk 
Javascript :: JavaScript Finding HTML Element by Id 
Javascript :: get index in map javascript 
Javascript :: js add multiple element to document 
Javascript :: mongoose number bigger 
Javascript :: stopwatch with javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =