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

123
Visualizações
Changing value after parsing from API

I'm parsing the following from:

    json.listMap.forEach((listItem: { State: string; Country: string})```

Response.data looks like this:
```{
  success: true,
  listMap: [
    {
      State : 'Northrine Westfalia',
      Country: 'Germany'
    },
    {
      {
      State : 'Bavaria',
      Country: 'Germany'
    }
    }
  ]
}

How can I convert the value in country currently being 'Germany' to 'Deutschland' after parsing it from the API using Java Script?

-> Let me be more open here. I don't really know that method I could use to do this. Maybe someone could point me at a documentation, of course I don't expect anyone to just hand me the code.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Use Array.map after parsing JSON into an JavaScript array:

const list = response.listMap.map(entry => {
  return {
    State : entry.State,
    Country: entry.Country.replaceAll('Germany', 'Deutschland')
  }
})

Of course, if you need JSON structure, just convert final array into JSON string with the following:

const newJSONList = JSON.stringify(list);
about 4 years ago · Juan Pablo Isaza Relatório

0

try this :

listMap = listMap.map(listMapItem => {
if ('Germany'===listMapItem.Country) {
    listMapItem.Country = 'Deutschland';
    return listMapItem;
} else {
    return listMapItem;
}
});
about 4 years ago · Juan Pablo Isaza Relatório

0

assuming below is your response object.

var responsObj={  success: true,
listMap: [
    {
      State : 'Northrine Westfalia',
      Country: 'Germany'
    },
      {
      State : 'Bavaria',
      Country: 'Germany'
    }
  ]
};
responsObj.listMap=responsObj.listMap.map(x=>{
  if(x.Country=="Germany"){
    x.Country="Deutschland";
  }
  return x;
});
console.log(responsObj.listMap);

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