How To Delete An Array Element Stored In Local Storage
In my simple TODO application i have a array list stored in my local storage. basically it is task lists. while deleting a task i want to delete the same task from local storage as
Solution 1:
You would need to get item, remove the index value and set the item again.
$scope.deleteTask = function(){
$scope.newTasks = localStorage.getItem("storedTasks");
$scope.newTasks.splice(this.$index, 1);
localStorage.setItem("storedTasks",JSON.stringify($scope.newTasks));
};
Solution 2:
Remove the same task at that index from localstorage using splice function.
$scope.deleteTask = function(){
$scope.tasks.splice(this.$index, 1);
$localStorage.storedTasks.splice(this.$index, 1);
};
Post a Comment for "How To Delete An Array Element Stored In Local Storage"