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

187
Views
How to compare objects of two arrays in JavaScript

I had taken two arrays in JavaScript

arr1 = ["empid","Name"];

arr2 = [{"keyName":"empid" ,"keyValue":"2"}]

And I want to check the value of keyName should be any one element from arr1.

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

0

some short-circuits after finding the first match so it doesn't necessarily have to iterate over the whole array of objects. And it also returns a boolean which satisfies your use-case.

const query1 = ['empid','Name'];
const arr1 = [{'keyName':'empid' ,'keyValue':'2'}];
const query2 = ['empid','Name'];
const arr2 = [{'keyName':'empid2' ,'keyValue':'five'}];
const query3 = ['empid','Name', 'test'];
const arr3 = [{'keyName':'test2' ,'keyValue':'five'},{'keyName':'test' ,'keyValue':'five'}];

function found(arr, query) {
  return arr.some(obj => {
    return query.includes(obj.keyName);
  });
}

console.log(found(arr1, query1));
console.log(found(arr2, query2));
console.log(found(arr3, query3));

about 4 years ago · Juan Pablo Isaza Report

0

Use _.isEqual(object, other); It may help you.

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!