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

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

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 Denunciar

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