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

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 :: nodejs heap usage 
Javascript :: Javascript convert object value to array 
Javascript :: javascript slice string from character 
Javascript :: uncheck checkbox based on id js 
Javascript :: format string javascript 
Javascript :: get main tr from td jquery 
Javascript :: splice from array javascript to remove 
Javascript :: what is undefined 
Javascript :: jquery placeholder 
Javascript :: react background gradient 
Javascript :: Scaling an image to fit on canvas 
Javascript :: filter array inside array of objects javascript 
Javascript :: javascript inbuilt funcctions to match the word and return boolean 
Javascript :: angular array export to excel 
Javascript :: how get count of letters in javascript 
Javascript :: function that duplicates data in array js 
Javascript :: nested navigation react native 
Javascript :: add getter to object javascript 
Javascript :: https express 
Javascript :: how to add a variable in js 
Javascript :: js array pop 
Javascript :: button dropdown not working on datatable search 
Javascript :: download datepicker js 
Javascript :: calculate two number and diplay next field without reload the page javascript 
Javascript :: js foreach key value 
Javascript :: Upload a file using ExpressJS+Multer 
Javascript :: get smallest value in array js 
Javascript :: javascript download image 
Javascript :: split and convert a string into object 
Javascript :: remove object property javascript es6 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =