I have an array of objects in local storage like this:
ios = [{
"id" : 1,
"type" : "in",
"cat" : "Diversi",
"qty" : 50,
"date" : "2016-11-02T09:51:48.872Z",
"descr" : ""
}, {
"id" : 1,
"type" : "in",
"cat" : "Lavoro",
"qty" : 50,
"date" : "2016-11-02T10:08:11.362Z",
"descr" : ""
}];
I want to delete one of the objects with this function:
function remove(io) {
var ios = localStorage.getItem('ios') ? JSON.parse(localStorage.getItem('ios')) : [];
var index;
for (var i = 0; i < ios.length; i++) {
if (ios[i] === io) {
index=i;
break;
}
}
ios.splice(index, 1);
localStorage.setItem('ios', JSON.stringify(ios));
}
But when i call the function, and pass it the parameter to delete, it doesn't delete the one I want, but the first one in local storage instead. Can anyone help me please?
if (ios[i] === io) {withif (JSON.stringify(ios[i]) === JSON.stringify(io)) {remove? Is it an object?