update localstorage value

 var persons = JSON.parse(localStorage.persons);

for (var i = 0; i < persons.length; i++) {

   if(inputName === persons[i].name){  //look for match with name

       persons[i].age += 2;  //add two

       break;  //exit loop since you found the person

   }

}

localStorage.setItem("persons", JSON.stringify(persons));

Comments

Popular posts from this blog

How to Add Firebase Analytics to Your NativeScript Mobile App

how to split array as per fixed length, and ionic two dates differences in min,seconds,hours