How best to work with localStorage?

localStorage.getItem('item') or localStorage.item
localStorage.setItem('item', 'blablabla) or localStorage.item = 'blablabla'
April 4th 20 at 13:11
3 answers
April 4th 20 at 13:13
Solution
You can read here.
If too lazy to read

const key = 'length';

localStorage[key] = 100;

console.log(localStorage[key]); // 0
console.log(localStorage.getItem(key)); // null

const key = 'length';

localStorage.setItem(key, 100);

console.log(localStorage[key]); // 1
console.log(localStorage.getItem(key)); // 100 (string)

April 4th 20 at 13:15
Solution

Note: It's recommended to use the Web Storage API (setItem, getItem, removeItem, key, length) to prevent the pitfalls associated with using plain objects as key-value stores.


https://developer.mozilla.org/en-US/docs/Web/API/W...
April 4th 20 at 13:17
Solution
How to work better with storage?

After reading the documentation

Find more questions by tags JavaScript