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

70
Vistas
Best way to map this object with array

I need to reach to the property: value in each drupal_internal__target_id: 2220, but i don't know how can i map to get that value. This is what i tried so far...

organismosId(){
// rel = data[0].relationships.organismo_auditado.data[0].meta.drupal_internal__target_id
// attr = included[0].attributes.drupal_internal__tid
this.buscadorService.getNodes()
.subscribe((data: InformesCounter) => {
    this.informesNode = data.data;
    const relationships = this.informesNode.map((data: { relationships: { organismo_auditado: { data: any; }; }; }) => data.relationships.organismo_auditado.data);
    console.log(relationships);
    const nodeRelationships = relationships.map((data: any) => data);
    console.log(nodeRelationships);
  })
}

And this is my JSON response of what i want to get:

enter image description here

The problem are the indexes like [0] and when i finally got there it returns undefined. Thanks

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

0

You can flat-map the overall data entries and internally map the data nodes inside the relationship metadata.

const run = () => {
  const ids = data.flatMap(({ relationships: { organismo_auditado: { data } } }) =>
    data.map(({ meta: { drupal_internal_target_id } }) =>
      drupal_internal_target_id));
  
  console.log(ids);
};

const data = [{
  relationships: {
    organismo_auditado: {
      data: [{
        id: '41ff8a06-c678-4db0-aa68-7887fd318345',
        meta: {
          drupal_internal_target_id: 2220
        }
      }]
    } 
  }
}, {
  relationships: {
    organismo_auditado: {
      data: [{
        id: 'c677dcc2-b7b7-4bf9-8cbf-c8c6faf9aa6f',
        meta: {
          drupal_internal_target_id: 2221
        }
      }]
    } 
  }
}];

run();

If you also want to include the ID, you can map objects:

const run = () => {
  const ids = data.flatMap(({ relationships: { organismo_auditado: { data } } }) =>
    data.map(({ id, meta: { drupal_internal_target_id } }) =>
      ({ id, drupal_internal_target_id })));
  
  console.log(ids);
};

const data = [{
  relationships: {
    organismo_auditado: {
      data: [{
        id: '41ff8a06-c678-4db0-aa68-7887fd318345',
        meta: {
          drupal_internal_target_id: 2220
        }
      }]
    } 
  }
}, {
  relationships: {
    organismo_auditado: {
      data: [{
        id: 'c677dcc2-b7b7-4bf9-8cbf-c8c6faf9aa6f',
        meta: {
          drupal_internal_target_id: 2221
        }
      }]
    } 
  }
}];

run();

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