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

94
Views
how to check property value in two array of object values javascript

I have two array of object values,

a1 and a2

if idvalue and cidvalue are equal, mainid and main are true

then return

true

else return

false

var result = a1.find(e=> a2.find(i=>i.cidvalue===e.idvalue));

var a1=[
  {id:1, idvalue: “teamA“,mainid: true, name: “ben4”}
]

var a2 =[
  {id:2, cidvalue: “teamA”, main: true, name: ”ben3”},
  {id:3, cidvalue: undefined, main: false, name: ”ben2”},
]



Expected Output

true

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

0

You're code is working exactely as intended.

Edit the match clause to this particular statement:

i => i.cidvalue === e.idvalue && e.mainid === i.main

And check out this working snippet with some tweaks using Array.prototype.every below to get back a boolean value indicating if the match was found or not:

const a1 = [
  { id: 1, idvalue: "teamA", mainid: true, name: "ben4" },
]

const a2 = [
  { id: 2, cidvalue: "teamA", main: true, name: "ben3" },
  { id: 3, cuid: undefined, main: false, name: "ben2" },
] 

const result = a1.every(e => a2.find(i => i.cidvalue === e.idvalue && e.mainid === i.main));
console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

here, I have list a2 with a1 and set if the data is more than 0 then true.

var a1 = [
    { id: 1, idvalue: "teamA", mainid: true, name: "ben4" }
]

var a2 = [
    { id: 2, cidvalue: "teamA", main: true, name: "ben3" },
    { id: 3, cuid: undefined, main: false, name: "ben2" },
]

console.log(a2.filter(item => a1.find(itemm => itemm.idvalue === item.cidvalue)).length > 0);

about 4 years ago · Juan Pablo Isaza Report

0

Use Array.every to compare each elements in array a1 against a2

var a1 = [
    { id: 1, idvalue: "teamA", mainid: true, name: "ben4" },
]

var a2 = [
    { id: 2, cidvalue: "teamA", main: true, name: "ben3" },
    { id: 3, cuid: undefined, main: false, name: "ben2" },
]

var result = a1.every(e => a2.find(i => i.cidvalue === e.idvalue && e.mainid && i.main));
console.log(result);

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!