从特定条件下存储在localStorage中的数组中删除对象?
16lz
2021-01-22
I have stored certain information in localStorage like-
我已将某些信息存储在localStorage中 - 如
$localStorage.recent = [{'id':1,'name':'abc','is_availbale':1},{'id':2,'name':'xyz','is_availbale':1},{'id':3,'name':'pqrs','is_availbale':0}];
having another array which is only having id's of certain people like(array_second can have only those id's which are already there in $localStorage.recent)-
拥有另一个只有某些人的id的数组(array_second只能拥有$ localStorage.recent中已有的那些id) -
array_second=['3'];
I want to delete those entries from $localStorage.recent which are corresponding to the id's in array_second. Expected output to be-
我想从$ localStorage.recent中删除那些与array_second中的id相对应的条目。预期产量为 -
$localStorage.recent = [{'id':1,'name':'abc','is_availbale':1},{'id':2,'name':'xyz','is_availbale':1}];
2 个解决方案
#1
0
You're just handling a standard array. The ngstorage library doesn't give you any additional functionality here.
你只是在处理标准数组。 ngstorage库在此处不提供任何其他功能。
For example:
$localStorage.recent = $localStorage.recent.filter((person) => {
return second_array.indexOf(person.id) !== -1;
});
更多相关文章
- Python 3.4:试图让这个模块对这个2d数组中的销售总数求和。不工作
- Python:2D Numpy数组(矩阵) - 查找负数之和(行)
- 如何在Python Django中附加数组字段
- 找到多维Python数组的维度[重复]
- 剑指offer python版 数组中只出现一次的两个数字
- 数组与矩阵---需要排序的最短子数组长度
- 在NumPy中更改数组边缘的值
- 将muilti维Json数组解析为Python
- python 中 字符串转换为数组,字典或表达式