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?
It is not a good solution but it works and is performative.
I found this here :
Seems like it only has getItem,setItem,removeItem,clear,key and length.
There's no
append
function. It's not hard to write one though:Note: It makes more sense to define a function
append
on thelocalStorage
object. However, becauselocalStorage
has asetter
, this is not possible. If you were trying to define a function usinglocalStorage.append = ...
, thelocalStorage
object will interpret this attempt as "Save an object calledappend
in the Storage object".