如何从JSON数组中删除下面代码中给出的项目。
[{"name":"John","city":"New York"},{"name":"abe","city":"New York"},{"name":"mathew","city":"New York"}]
答案 0 :(得分:0)
你可以使用javascript拼接功能
YourArray.splice(0, 1);
其中0
将是需要删除的密钥,1
将是需要从该密钥中删除的项目数。
答案 1 :(得分: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