how to save something to local storage javascript code example

Example 1: javascript localstorage

localStorage.setItem("user_name", "Bob");

document.body.addEventListener("click", function(){
  alert(localStorage.getItem("user_name"))
});

Example 2: get localstorage

var pull=JSON.parse(localStorage.getItem('data'))
for(var i=0; i<pull.length; i++){
    new ConstrcterName(pull[i].AnyName, pull[i].AnyName, pull[i].AnyName)
}
for(var o=0; o<arrayName.length; o++){
    ArrayName[o].getRandom();
    ArrayName[o].showRow();