Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const storage = {
- has(key) {
- return !!localStorage.getItem(key);
- },
- get(key) {
- return JSON.parse(localStorage.getItem(key));
- },
- set(key, value) {
- localStorage.setItem(key, JSON.stringify(value));
- }
- };
- //Usage with jQuery 3.3.1 (onload)
- (function(){
- storage.set('yourkey', 'CTH001239');
- if(storage.has('yourkey')){
- console.log(storage.get('yourkey'));
- console.log('Found!');
- } else {
- console.log('Not found!');
- }
- })();
Add Comment
Please, Sign In to add comment