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

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

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 Denunciar

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 Denunciar

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