i have the following code in my html page and as you can see i am trying to replace the occurrence of "state"
with "item"
and "number"
with "count"
in the string s
here is an example of the response text : [{"number":177,"state":"ABONDONNE"},{"number":132,"state":"ENCOURS"},{"number":6,"state":"GAGNE"},{"number":195,"state":"PERDU"},{"number":2,"state":"REPORTE"}]
here is my javascript code:
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
var s = xhttp.responseText;
s.replaceAll("state","item");
s.replaceAll("number","count");
var jsonArray = JSON.parse(s);
console.log(s);
}
xhttp.open("GET","http://localhost:8080/plot");
xhttp.send();
my problem is that after this code i get the same response text in the console:
[{"number":177,"state":"ABONDONNE"},{"number":132,"state":"ENCOURS"},{"number":6,"state":"GAGNE"},{"number":195,"state":"PERDU"},{"number":2,"state":"REPORTE"}]
what i am missing?