One function I want to do is to set an empty array to localstorage, and push the currently clicked data into the localstorage array every time it is clicked. However, localstorage does not allow push. I have tried deep copying the localstorage array and then pushing it. In the deep copy array, I set the localstorage array to the deep copy array, but I haven’t tried it yet. Please give me some advice
localStorage can only store String, you need to use Json object to convert it:
It’s very simple. Convert it to json string before saving it, then take it out and reverse it to get a normal array.
Very strange thinking, why not push into the array in localStorage.setItem("arr", arr), but set localStorage first and then perform the operation
Arrays stored in localstorage will become strings.
If you want to operate the variables of localStorage, you need to take them out first and then store them in.
Take it out and set it up again
Dear, first of all, you need to understand what localstorage is.
localstorage is a permanent storage method in webStorage technology in the new features of HTML5. We usually also call it local storage and cross-session storage.
His usage does not require setting an empty array for localstorage. It has its own method of accessing data, as follows:
Hope it can help you~