Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda