How do i delete an items from JSON array which is given in the code below.
[{"name":"John","city":"New York"},{"name":"abe","city":"New York"},{"name":"mathew","city":"New York"}]
How do i delete an items from JSON array which is given in the code below.
[{"name":"John","city":"New York"},{"name":"abe","city":"New York"},{"name":"mathew","city":"New York"}]
you can use javascript splice function
YourArray.splice(0, 1);
where 0
will be the key which need to be removed and 1
will be the number of items which need to be removed from that key.
var a = localStorage.getItem("tasks"); // get the tasks from localstorage
a = JSON.parse(a); // convert from string to array
a.splice(0,1); // splice the array -> 0 = index of item to be removed, 1 = no of items to be removed
localStorage.setItem("tasks",JSON.stringify(a)); // set the updated task list in localstorage