Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove ıtem on localStorage?

I want to removeItem on localstorage but ı dont use localstorage.removeItem().Because ı want to delete a index in array(Sepet=array)
How can ı do it ?
thx

Sepet Array

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To get object from localStorage you need the Helper: localStorage.getItem('objectName');. You will get a string and not a object. To transform this string to a Object you need the function JSON.parse(string). And on this point you can work with the object. If you will delete item by index then remove it with object[index]and if you will remove item by value key like id: 2 then use JS Object function function like spliceto remove this item.

After that you have to stringify the object again to a string with JSON.stringify(object). This string you can store in the lcoalStorage withe the methode: localStorage.set(string)

That is the entire workflow.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading