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

js filter array of objects by another object

var filtered = myArray.filter(function(i){
    return myFilter.some(function(j){
        return !Object.keys(j).some(function(prop){
            return i[prop] != j[prop];
        });
    });
});

console.log(filtered);
Comment

PREVIOUS NEXT
Code Example
Javascript :: set up node js server express 
Javascript :: pass number as a prop in react 
Javascript :: change favicon with javascript 
Javascript :: create a new input with type checkbox javascript 
Javascript :: javascript byte array to hex string 
Javascript :: javascript loop through array backward 
Javascript :: mongodb find like 
Javascript :: js string for each char 
Javascript :: js regex valid name 
Javascript :: mui image 
Javascript :: js get string before character 
Javascript :: js is directory 
Javascript :: js check string for pangram 
Javascript :: remove last character from string jquery 
Javascript :: see if discord message is in dm discord.js 
Javascript :: react native remove darkmode 
Javascript :: javascript get text between two words 
Javascript :: if string javascript 
Javascript :: read json file flutter 
Javascript :: android resource linking failed react native image crop picker 
Javascript :: generate random boolean javascript 
Javascript :: upload files in react using axios 
Javascript :: how to check if object is undefined in javascript 
Javascript :: javascript get highlighted text 
Javascript :: js validate date object 
Javascript :: javascript detect collision 
Javascript :: python json string to object 
Javascript :: js convert set to array 
Javascript :: useeffect umnount 
Javascript :: mui usetheme 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =