Storage: phương thức clear()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Phương thức clear() của giao diện Storage xóa tất cả các khóa được lưu trong một đối tượng Storage nhất định.
Cú pháp
js
clear()
Tham số
Không có.
Giá trị trả về
Không có (undefined).
Ví dụ
Hàm sau tạo ba mục dữ liệu trong local storage, rồi xóa chúng bằng clear().
js
function populateStorage() {
localStorage.setItem("bgcolor", "red");
localStorage.setItem("font", "Helvetica");
localStorage.setItem("image", "miGato.png");
localStorage.clear();
}
Note: Để xem ví dụ thực tế, hãy xem Web Storage Demo.
Thông số kỹ thuật
| Specification |
|---|
| HTML> # dom-storage-clear-dev> |