Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda