默认localStorage只能存取字符串 那么如何存取数组呢 let newlist = [] localStorage.setItem('recent', JSON.stringify(newlist)) let list = JSON.parse(localStorage.getItem('recent'))
项目背景是需要将搜索历史存储到localStorage中, 需要存储id和name,每次存储时都需要在记录中多加一条,用数组push显然是比较好的方法,但localStorage不方便存储数据,于是就想到来存储字符串,用‘逗号’隔开,然后再split('',")转化成数组,代码如下: let history = localStorage.historyData?localStorage.getItem("historyData"):''; let item = data +
我们有时候会遇到一个问题将两个数组一一对应的压缩起来: 两个都是字符串: 列表解析[''.join(i) for i in zip(list_1, list_2)] map(lambda x,y:x+y, list_1, list_2) 两属性不相同 ['%s%s'%(a,b) for (a,b) in zip(list_1, list_2)] 这样生成了一个一维的二元数组[[(element1,element2)]],两个列表进行合并 1 ht1 = [(param_1, param_1) f
题目:We once did a lot of recursional problem . I think some of them is easy for you and some if hard for you.Now there is a very easy problem . I think you can AC it. We can define sum(n) as follow: if i can be divided exactly by 3 sum(i) = sum(i-1)