On the problem of storing data in localStorage

enter the page, call the interface, request to the data list, and then store the list in localStorage:

localStorage.setItem("array", JSON.stringify(list));

then exit the page, enter again, and get the data again. What does list, need to do now to push this newly requested list to an existing localStorage? If you try for a long time, you will only cover it, but you can"t push it. Please help! Thank you very much!


although you do not approve of this, but if you insist on doing so, you can create a new array variable. Every time you call the interface, the array returned by the push interface will be put into the array variable, and then stored.

var arr = [];
arr.push(list);
localStorage.setItem("array", JSON.stringify(arr));

I don't understand why you want to operate in this way. You have re-acquired the data in list, reasonable localStorage is out-of-date data, so there is no problem with overwriting. If your original intention is to update the data in localStrorage, you can insert it after comparing the old data with the new data


.

arr / / New array

let newArr=JSON.parse(localStorage.array).push(arr)
localStorage.setItem("array", JSON.stringify(newArr));
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30242-2b53a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30242-2b53a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?