Delete data from json array

后端 未结 3 1133
故里飘歌
故里飘歌 2021-02-15 00:11

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条回答
  •  甜味超标
    2021-02-15 01:13

    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.

提交回复
热议问题