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

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

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