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

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

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