Determines whether an object is an empty object:
var obj ={};
1.
if (json.stringify (newobj) = = "{}") {
Console.log (' Kongduixiang ')
}else{
Console.log (' hehe ')
}
2.
if (Object.keys (newobj). length = = 0) {
Console.log (' Kongduixiang ');
}
Localstorage and Sessionstorage differences:
Localstorage and Sessionstorage are the same objects that are used to store client temporary information.
They can only store objects of the string type (although other primitive types of objects can be stored in the specification, but so far no browser has implemented them).
The Localstorage life cycle is permanent, which means that the information will always be present unless the user is shown to clear Localstorage information on the UI provided by the browser.
The Sessionstorage life cycle is the current window or tab, and once the window or tab is permanently closed, all data stored through sessionstorage is emptied.
The information in Localstorage or sessionstorage cannot be shared by different browsers. The same localstorage can be shared between different pages in the same browser (the page belongs to the same domain name and port), but sessionstorage information cannot be shared between pages or tabs. It is important to note that pages and tabs refer only to top-level windows, and if a tab contains multiple IFRAME tags and they belong to the same-origin page, they can be shared sessionstorage.
Homologous Judgment rules: (Protocol, hostname, port number)
Http://www.test.com
Https://www.test.com (different sources, because the protocol is different)
Http://my.test.com (different source, because host name is different)
http://www.test.com:8080 (different sources, because the ports are different)
Localstorage and Sessionstorage Use the same API when using:
Localstorage.setitem ("Key", "value");//Store a value "value" for the name "key"
Localstorage.getitem ("key");//Get a value named "Key"
To enumerate Localstorage methods:
for (Var i=0;i<localstorage.length;i++) {
var name = Localstorage.key (i)?;
var value = Localstorage.getitem (name);?
}
To delete a method that stores information in Localstorage:
Localstorage.removeitem ("key");//delete the information named "Key".
Localstorage.clear ();? Empty all information in Localstorage
The information obtained through GetItem or directly using localstorage["key" is a copy of the actual store.
For example:
Localstorage.key = {value1: "value1"}?;
Localstorage.key.value1= ' a '?;
There is no way to do this. The following writing does not work for the actual stored value:
? Localstorage.getitem ("Key"). Value1= "a";
JavaScript determines whether an object is an empty object, Localstorage and Sessionstorage differences