Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How filter array of objects based on objects exists in another array of objects?

I have

array1 = [{ name: sample1 }, { name: sample2 }, { name: sample3 }];
array2 = [{ name: sample1 }, { name: sample2 }];

I want to filter objects of array1 which exists in array2. So I need to have

[{ name: sample1 }, { name: sample2 }]

How can I get it in javascript?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use .filter and .some function in JavaScript , Here is the example

const array1 = [{ name: "sample1" }, { name: "sample2" }, { 
name: "sample3" }];
 const array2 = [{ name: "sample1" }, { name: "sample2" }];
let Result = array1.filter(function(obj) {
  return array2.some(function(obj2) {
    return obj.name== obj2.name;
});
}); 
console.log(Result)
about 4 years ago · Juan Pablo Isaza Report

0

You can use object destructuring, the map() and .includes() methods as shown below:

const array1 = [{ name: "sample1" }, { name: "sample2" }, { name: "sample3" }];
const array2 = [{ name: "sample1" }, { name: "sample2" }];

const filtered = array1.filter(
    ({name}) => array2.map(o => o.name).includes(name)
);

console.log( filtered );

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!