Home > Article > Web Front-end > How to use sessionStorage in js? Basic usage of sessionStorage
The content of this article is to introduce how to use sessionStorage in js? Basic usage of sessionStorage. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
sessionStorage is one of the browser data storage methods. It is used to temporarily save the data of the same window. After closing the window, the sessionStorage data will not exist. It is stored in the form of key value pairs.
Basic usage
Save value
sessionStorage.test="1212";
Get value
var test=sessionStorage.test;
Delete
sessionStorage.removeItem("test");
Remember to delete directly
sessionStorage.test=undefined
The last sessionStorage.test will be equal to "undefined" and will not achieve the effect of deletion
Clear Data Clear the data stored in the current session
sessionStorage.clear();
Total number of sessionStorage
sessionStorage.length
Traverse sessionStorage
for(var i=0;i<sessionStorage.length;i++){ var key=sessionStorage.key(i); var value=sessionStorage[key]; }
The above is the detailed content of How to use sessionStorage in js? Basic usage of sessionStorage. For more information, please follow other related articles on the PHP Chinese website!