I have a JSON that I get from localStorage where I keep the names of the players and their scores for a game, then I receive them in 2 separate variables to be able to modify the score and increase its value if the player wins. What I want to do is that when the player wins, delete the JSON element and then reinsert it with the modified score value and save it back to localStorage.
That's how I get the JSON:
var Jugadores = localStorage.getItem("Jugadores");
Jugadores = JSON.parse(Jugadores);
This JSON filled it in another html where the players register and in the game page this is what I get in console:
["{"player":"leader","score":0}",
"{"player":"lel","score":0}",
"{"player":"lol","score":0}"]
Also in the player's html I keep individually the player and punctuation values to be able to modify them and then replace the previous object (this I also use in an if in case the player does not yet exist the score is 0 by default):
jugador =$('#txtplayer').val();
var player = jugador;
var score = 0;
localStorage.setItem("player",player);
localStorage.setItem("score",score);
And so I receive them in the html of the game:
var player = localStorage.getItem("player");
var score = localStorage.getItem("score");
Thank you in advance.