I am trying to save strings to local storage submitted from a textbox and submit button. However the data overwrites every time a new string is submitted as the key stays the same. How do I use a new key every time so data is saved. I view the key value pairs via inspect.
I have tired using the following but .length is just reding the length of the string and is not correct. I have also tried localStorage.length. Is there a simple solution to this, it doesnt have to be a for loop. I have researched but not understood anything.
function setLocalStorage() {
let data = document.getElementById( textBox ).value;
for (let i = 0; i < data.length; i++){
localStorage.setItem("Key" + (i + 1), data)
};
document.getElementById("textBox").value = "";
}