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
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 answers
Answer question

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 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!