-2

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"}]   
lx6002
  • 39
  • 11
  • Image does not exist and you should not post code in an image..... – epascarello Apr 04 '18 at 18:46
  • Possible duplicate of [How do I remove a property from a JavaScript object?](https://stackoverflow.com/questions/208105/how-do-i-remove-a-property-from-a-javascript-object) – ecg8 Apr 04 '18 at 18:48
  • @ecg8 - close, but this question is about removing an entry in an array, not a property from an object. I'm sure there's another duplicate out there for that particular case as well, though. – Alexander Nied Apr 04 '18 at 18:49
  • I would say this is the more likely duplicate: https://stackoverflow.com/questions/5767325/how-do-i-remove-a-particular-element-from-an-array-in-javascript – Alexander Nied Apr 04 '18 at 18:51
  • @Alexander Nied, you are probably right. When I flagged it the image was still unavailable. – ecg8 Apr 04 '18 at 18:53
  • Possible duplicate of [How do I remove a particular element from an array in JavaScript?](https://stackoverflow.com/questions/5767325/how-do-i-remove-a-particular-element-from-an-array-in-javascript) –  Apr 09 '18 at 06:28

2 Answers2

0

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.

Mark
  • 90,562
  • 7
  • 108
  • 148
Taylor Rahul
  • 709
  • 6
  • 19
0
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
Arpit Arya
  • 123
  • 6