DEV Community

duccanhole
duccanhole

Posted on

4 1

simple way to store data in js

You want a simple way to store data? In javascript, you can use window.localStorage.
localStoge allows you store any information in browser. It is new feature of HTML5, and using method is similar to hashmap(with key and value). To store data, use this syntax:

localStorage.setItem(key, value);
Enter fullscreen mode Exit fullscreen mode

And to get data, use:

localStorage.getItem(key);
Enter fullscreen mode Exit fullscreen mode

localStorage also provide method to delete data:

localStorage.removeItem(value); //delete one
localStorage.clear(); //delete all
Enter fullscreen mode Exit fullscreen mode

Read more about document: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
Because it's pretty basic and simple, localStorage only store string data, if data is more complex, it becomes useless. Addition, the limit of data is small(about 5mb); and it has not security. Therefore, think carefully before use localStorage.

Top comments (0)

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay