How to add text to an object in the browser localSorage instead of replacing it

question:
how do I add text to an object in the browser localSorage instead of replacing it?

Mar.22,2021

first take it out and merge it in set


localStorage.setItem ("name", "caibin") / / Store the variable with the name caibin
localStorage.getItem ("name") / / caibin, reads the value of the variable named name in the localStorage object
localStorage.removeItem ("name"); / / Delete name
localStorage.clear () / clear the cache


localStorage.setItem("name",localStorage.getItem("name") + "test")
< hr class= "answer"
const appendTextForStorage = storage => (key, value)  => 
   storage.setItem(key, (storage.getItem(key) || '') + value)

const appendTextForLocalStorage = appendTextForStorage(window.localStorage)


appendTextForLocalStorage('hello', 'world')
appendTextForLocalStorage('hello', 'world2')

// test
console.log(window.localStorage.getItem('hello') === 'worldworld2') // true

I hope my answer will be helpful to you.

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-1e5b10d-455f8.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-1e5b10d-455f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?