Home Web Front-end JS Tutorial A brief introduction to the use of localStorage method in js

A brief introduction to the use of localStorage method in js

Aug 22, 2018 pm 05:00 PM
localstorage

This article brings you a brief introduction to the use of the localStorage method in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

localStorage provides several methods:

1. Storage: localStorage.setItem(key, value)

If the key exists, update the value

2. Get: localStorage.getItem(key)

If the key does not exist, return null

3. Delete: localStorage.removeItem(key)

Once deleted, the corresponding key All data will be deleted

4. Clear all: localStorage.clear()

Sometimes it is too troublesome to use removeItem to delete one by one. You can use clear. The consequence of execution is that all localStorage objects will be cleared. Saved data

5. Traverse the total amount of key

.length stored in localStorage, for example: localStorage.length
.key(index) to obtain the key, for example: var key=localStorage .key(index);

6. Store JSON format data

JSON.stringify(data) Convert an object into a JSON format data string and return the converted string
JSON .parse(data) parses the data into an object and returns the parsed object

Note: The data stored in localStorage cannot be shared across browsers. A browser can only read the data of its own browser. Storage space 5M.

Related recommendations:

jQuery localStorage implements timer

How to use localstorage and sessionstorage in Vue

The above is the detailed content of A brief introduction to the use of localStorage method in js. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌