localStorage

localStorage.setItem( key, val)數組

localStorage.getItem( key)spa

localStorage[key] = JSON.stringify(數組);code

data = JSON.parse(localStorage[key]);字符串

localStorage.setItem( 'name', JSON.stringify({name:1}))
localStorage.getItem( 'name')
"{"name":1}"get

localStorage.setItem( 'name', JSON.stringify([1,2,3,4]))
localStorage.getItem( 'name')
"[1,2,3,4]"
JSON.parse(localStorage.getItem( 'name'))
[1, 2, 3, 4]string

字符串存儲 取出也是字符串類型it

localStorage.setItem( 'num', 1)
localStorage.getItem( 'num')
"1"class

若是已知存儲的內容,單數字能夠強轉,必定要轉換成數字才能使用word

相關文章
相關標籤/搜索