So I have this code here
var i = 0;
function contactUs(event){
event.preventDefault();
var lettre = new message();
sessionStorage.setItem("lettreNo" + i++, JSON.stringify(lettre));
$("form")[0].reset();
}
But I know it's wrong because the key won't increment, it will just override the thing, if I go to another page and come back since this script is used by all my pages, how do I fix this?
Just store an array inside one storage property:
Or if you really want this complicated key thing, it makes sense to create a helper:
Usable as: