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

106
Views
Find the index of element in an array against another array

Say I have two arrays of objects

arrayOne = [{revision: { id: 1 }}, {revision: { id: 2 }}, {revision: { id: 3 }}, {revision: { id: 4 }}]

arrayTwo = [{someOtherProp: { id: 2 }}, {someOtherProp: { id: 4 }}]

How do I check the ids in arrayTwo against ids in arrayOne and returns the result index of the similar id occurrences like so [1, 3] (based on arrayOne we can see on index 1 and index 3 have ids that occur in arrayTwo)

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

This should work

arrayOne = [{revision: { id: 1 }}, {revision: { id: 2 }}, {revision: { id: 3 }}, {revision: { id: 4 }},{revision: { id: 5 }}];

arrayTwo = [{someOtherProp: { id: 2 }}, {someOtherProp: { id: 4 }}];

console.log(arrayOne.filter(o1 => arrayTwo.some(o2 => o1.revision.id === o2.someOtherProp.id)).map(x => arrayOne.findIndex(y => y.revision.id === x.revision.id))); // [1, 3]
about 4 years ago · Juan Pablo Isaza Report

0

This should work for your case:

one = [{revision: { id: 1 }}, {revision: { id: 2 }}, {revision: { id: 3 }}, {revision: { id: 4 }}]

two = [{someOtherProp: { id: 2 }}, {someOtherProp: { id: 4 }}]

for(let i in two) {
  for(let j in one) {
    if(two[i]['someOtherProp']['id']==one[j]['revision']['id']){
      console.log(i,j)
    }
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

You can use this implement:

arrayOne = [{revision: { id: 1 }}, {revision: { id: 2 }}, {revision: { id: 3 }}, {revision: { id: 4 }},{revision: { id: 5 }}];
arrayTwo = [{someOtherProp: { id: 2 }}, {someOtherProp: { id: 4 }}];

arrayTwo.map(v=>{return v['someOtherProp']['id']}).map(v=>{
    return arrayOne.map(v=>{return v['revision']['id']}).indexOf(v)
})
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!