xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

localStorage access methods All In One

localStorage access methods All In One

  1. API

  2. object property

调用 Local Storage API 而不再“直接”访问 Local Storage。
这两种方法都是有效的,但是调用 API 往往是更值得推荐的方法。

typeof localStorage;
"object"

localStorage.getItem('algoliasearch-client-js');
"{\"BH4D9OD16A\":{\"hostIndexes\":{\"read\":0,\"write\":0},\"timeoutMultiplier\":1,\"shuffleResult\":[1,3,2],\"lastChange\":1615047026850}}"

localStorage['algoliasearch-client-js'];
"{\"BH4D9OD16A\":{\"hostIndexes\":{\"read\":0,\"write\":0},\"timeoutMultiplier\":1,\"shuffleResult\":[1,3,2],\"lastChange\":1615047026850}}"

localStorage.name = 'eric';
"eric"

localStorage;
Storage {algoliasearch-client-js: "{"BH4D9OD16A":{"hostIndexes":{"read":0,"write":0},…uffleResult":[1,3,2],"lastChange":1615047026850}}", name: "eric", length: 2}algoliasearch-client-js: "{\"BH4D9OD16A\":{\"hostIndexes\":{\"read\":0,\"write\":0},\"timeoutMultiplier\":1,\"shuffleResult\":[1,3,2],\"lastChange\":1615047026850}}"length: 2name: "eric"__proto__: Storage

Array.isArray(localStorage)
false

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-03-07 13:25  xgqfrms  阅读(47)  评论(4)    收藏  举报