【Front end tutorial】localstorage

localstorage is a local storage method

What is localSotrage

localStorage is permanently stored on the browser side unless it is actively cleared.

localStorage is statically stored locally in the browser, has nothing to do with the http protocol, and is not carried in the http request packet

LocalStorage stores key-value data and is always stored as a string


localstorage

How to use localstorage

localStorage.setItem (‘name’, ‘Bill Gates’);

Add or modify the key in the store to name and its value to ‘Bill Gates’

1
localStorage.setItem('name', 'Bill Gates');

localStorage.getItem(‘name’)

Get the value corresponding to key in the store

1
localStorage.getItem('name');

localStorage.removeItem(‘name’);

Delete data with key name in storage

1
localStorage.removeItem('name');

localStorage.clear();

Clear local storage

1
localStorage.clear();
Persist in original technology sharing, your support will encourage me to continue to create!