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

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

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 Relatório

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