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

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

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 Report

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 Report

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