//1.把数组转换为对象存入
let arr = [{id:1,name:'测试1'},{id:2,name:'测试2'}]
sessionStorage.setItem('data', JSON.stringify(arr))
//2.获取缓存
const data= JSON.parse(sessionStorage.getItem('data'))
console.log(data)
//1.把数组转换为对象存入
let arr = [{id:1,name:'测试1'},{id:2,name:'测试2'}]
sessionStorage.setItem('data', JSON.stringify(arr))
//2.获取缓存
const data= JSON.parse(sessionStorage.getItem('data'))
console.log(data)
本文标题:JavaScript缓存数组
本文链接:https://www.haomeiwen.com/subject/fqhyyrtx.html
网友评论