adding objects to array in localStorage

后端 未结 5 1810
轮回少年
轮回少年 2021-01-11 10:44

Ok, I\'ve tried to follow examples here, I know there might be a few different ways of adding objects to an array in localstorage and not overwriting it but I\'m failing to

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-11 11:34

    Maybe you just need to fetch the entries before pushing the new one:

    var allEntries = JSON.parse(localStorage.getItem("allEntries")) || [];
    allEntries.push(entry); 
    //etc...
    

提交回复
热议问题