Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading