I'm a bit lazy with JavaScript and I'm trying to create an array of objects to save data from a form with localStorage
, but I'm not sure how to do that.
I have already created the code to save the data in the local store, but only save an object, whenever I reload the page and fill in the data again, the old data is overwritten.
I want to create an array to put 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");
}