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

127
Views
How to format response to populate select in react native

Im trying to format the items that came in Terminals field to an Array of { key, label } in order to populate a dropdown

    Object {
        "Status": "SUCCESS",
        "Terminals": Object {
          "0": Object {
            "name": "GENESIS- DEMO Terminal",
            "term_id": "GENESIS",
          },
          "1": Object {
            "name": "GENESIS- DEMO Terminal",
            "term_id": "GENESIS",
          },
          "name": "",
          "term_id": "",
        },
        "TotalCount": 1
    }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You have Total count in your response, so based on that total count read each data from the object and push it to the options variable A simple for loop can solve this problem

Check my code

let response = {
        "Status": "SUCCESS",
        "Terminals":  {
          "0": {
            "name": "GENESIS- DEMO Terminal",
            "term_id": "GENESIS",
          },
          "1": {
            "name": "GENESIS- DEMO Terminal",
            "term_id": "GENESIS",
          },
          "name": "",
          "term_id": "",
        },
        "TotalCount": 2
    }

let options = [];
for(let i=0; i<response.TotalCount; i++) {
  options.push({key:response.Terminals[i].term_id, label: response.Terminals[i].name})
}

console.log(options)

about 4 years ago · Juan Pablo Isaza Report

0

Using Object.values()

const data  = {
  "Status": "SUCCESS",
  "Terminals":  {
     "0":  {
        "name": "GENESIS- DEMO Terminal",
        "term_id": "GENESIS",
      },
      "1":  {
        "name": "GENESIS- DEMO Terminal",
        "term_id": "GENESIS",
      }
    },
    "TotalCount": 1
};
    
 const dropDownArray = Object.values(data.Terminals).map(({ name: label, term_id: key }) => ({ key, label }));
 console.log(dropDownArray);

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!