I have stored data in local storage in an array. Now I want to remove certain item from that array present in local storage. For that first I have
var items = JSON.parse(localStorage.getItem('shoppingCart'));
var resturantid = localStorage.getItem('resturant_id');
var filtered = [];
for (var q = 0; q < items.length; q++) {
if (items[q].resturantid == resturantid) {
filtered.push(items[q]);
}
}
console.log(typeof filtered, filtered);
output is OBJECT
in console
(2) [{…}, {…}]
0: {name: "veg-momo", price: 12, count: 8, resturant: "Test Developer", resturantid: 2, …}
1: {name: "afdafasdf", price: 123, count: 4, resturant: "Test Developer", resturantid: 2, …}
length: 2
__proto__: Array(0)
typeof
gives me object and because of this I haven't been able to use map
function as it says array.map
is not a function.
I want these things to happen just to remove certain item in local storage key in which array is set.