I do a
localStorage.setItem('oldData', $i("textbox").value);
to set the value of key oldData to the value in a textbox.
The next time something is entered to the textbox, I want to append to the already existing oldData.
So, if I enter apples and then oranges in my textbox, my localStorage key oldData should look like this:
Initially:
Key | Value
---------------------------
oldData | apples
Now:
oldData | apples oranges
How can I append? Is there an append method provided?
Or do I need to read the data first, append in javascript and then write back?
There’s no
appendfunction. It’s not hard to write one though:Note: It makes more sense to define a function
appendon thelocalStorageobject. However, becauselocalStoragehas asetter, this is not possible. If you were trying to define a function usinglocalStorage.append = ..., thelocalStorageobject will interpret this attempt as “Save an object calledappendin the Storage object”.