I want to save the value of the input into the local storage upon button click.
allNames = []
function submit() {
let names = document.getElementById("names").value;
allNames.push(names);
localStorage.setItem("totalNames", JSON.stringify(allNames))
console.log(JSON.parse(localStorage.getItem("totalNames")))
}
<button onclick="submit()">Submit</button>
<input id="names" placeholder="Enter Name">
I want to save the value of the name the user enters into the input to local storage so even after the page refreshes, the name will be saved.