4
I’m a little layy with Javascript and I’m trying to create a array of objects to save data from a form with the localStorage
, but I don’t know how to do it.
I already created the code to store the data in the local storage, but saves only one object, whenever I reload the page and fill in the data again, the old data is overwritten.
I want to create a array to place all the objects I create.
Code:
function salvarPessoa(){
var nome = document.getElementById("nome").value;
var cpf = document.getElementById("cpf").value;
var pessoa = {nome: nome, cpf: cpf};
pessoa_json = JSON.stringify(pessoa);
localStorage.setItem("pessoa", pessoa_json);
alert("Salvo com Sucesso");
}