javascript - push multiple array object into localhost? -
(function{ var array = localstorage.getitem('id') || []; obj = {}; obj.id=1; array.push(obj); localstorage.setitem('id',json.stringify(array)); }();
why in localstorage doesn't insert obj twice? i'm seeing replace existing one.
it replace existing one.
try this:
if(localstorage.getitem('id')){ array = json.parse(localstorage.getitem('id')) } else { var array = []; } obj = {}; obj.id=1; array.push(obj); localstorage.setitem('id',json.stringify(array));
everytime adding first gets localstorage item , adds , puts back.
Comments
Post a Comment