Delete data from json array

后端 未结 3 1667
清歌不尽
清歌不尽 2021-02-15 00:29

I am trying to remove a piece of a data from a json array. For example I have this array

var favorites =    {
        \"userID\": \"12345678\",
        \"favorit         


        
3条回答
  •  梦毁少年i
    2021-02-15 00:55

    If you want to actually remove an item from the array so that all items after it in the array move down to lower indexes, you would use something like this:

    favorites.favorites[1].items.splice(1, 1);
    

    You want to operate on the actual items array which means calling methods on the items array. For .splice(), you pass the index where you want to start modifying the array and then the number of items to remove thus .splice(1, 1) which will remove 1 item starting at index 1.

提交回复
热议问题