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

95
Vistas
Check objects inside same array and different array

I'm studying a bit of js objects lately (I'm still learning). I'm stucked on a project of mine where I need to check if 2 objects inside an array (of objects) are identical between them and between them and another object in a different array. These two initial objects will have to behave differently if certain instances occurs:

I'll try to be as clear as possible. My code has 2 arrays of objects:

let array1 = [{name: "New York", value: "A", price: 43, status: "not checked"},
             {name: "Not Specified", value: "A", price: 333, status: "not checked"},
             {name: "Barry", value: "C", price: 48, status: "not checked"},..etc.];

let array2 = [{name: "John", value: "A", price: 23, status: "not checked"},
             {name: "Jerry", value: "A", price: 67, status: "not checked"},
             {name: "Barry", value: "C", price: 48, status: "not checked"},                 
             {name: "Tom", value: "F", price: 23, status: "not checked"},
             {name: "Barry", value: "C", price: 48, status: "not checked"},...etc.];

As you can see initial status of every objects is "not checked". Now, part of my code loops one array (array2, the bigger of the two) to check if, at the same position "i", they have objects inside with different properties/values:

 for (let i = 0; i < array2.length; i++){
    if (array1[i].value != array2[i].value){
    ...do something...}.

Now, as you can see there is also one result in common in array1 and array2:

{name: "Barry", value: "C", price: 48, status: "not checked"}
  

What I would like to do is this:

  • staying inside the original for loop, when I arrive at "i" position of "Barry", I want to check if in array2 there are at least 2 objects identical between them (in this case the "Barry" one). If yes then:
  • check if these two are identical to any object in array1 (always "Barry", this time in array1, here the "i" position can be random). If yes then:
  • while the loop is still cycling at "i" position of the first "Barry" result, the first result will do something, while the other identical one (always in array2) will behave differently (so I was thinking to modify the status of the first result to "checked", so the subsequent result, will have to verify that having a different status, "not checked", need to behave differently). Nothing happens to the result in array1.

I'm sorry for the wall of text, but being pretty noob is hard to describe sometimes what I'm trying to do. Thanks for any suggestion!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You will need to call a find function for each element in the first array. Something like this:

array1.forEach(item => {
  var found = array2.find(item2 => item2.value === item.value)
  if (found) {
    // do something
  }
}
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