Delete Array From Object In Localstorage
When I click on a button I load the function 'DeleteFromlocalStorage' with the parameter 'id'. This is my function 'DeleteFromlocalStorage': function DeleteSessionFromLocal
Solution 1:
I may be wrong but here is what you want to do:
Either localStorage.removeItem(key);
Or if ifs something within the localStorage JSON item then do:
functionDeleteSessionFromLocalStorage(data)
{
var id_session = data;
//Not sure but you might need to do JSON.parse(a) after to get it
a = localStorage.getItem('session');
delete a.dataalert(a);
}
Solution 2:
Your code sample just looks like a javascript object to me. In which case you can use the 'delete' keyword. Good discussion here:
How do I remove a property from a JavaScript object?
So something like
delete a["21114"]
Solution 3:
for(obj in json) {
if(json[obj].id == id_session)
{
delete json[obj];
}
}
localStorage.setItem('session', JSON.stringify(json));
Get the objects, check every id of every object and delete the ones with the id = "id_session".
Post a Comment for "Delete Array From Object In Localstorage"