2021年3月7日星期日

Push new data to array, if indices match

I have a variable called "animeData" that contains an array of objects.

{"table":[{"id":1,"name":"K-on","redirect":"k-on","thumbnail":"/images/anime/k-on/thumbnail.jpg","characters":[{"name":"azusa","thumbnail":"/images/anime/k-on/azusa.jpg","votes":[{"ip":"127.0.0.1"}]},{"name":"mio","thumbnail":"/images/anime/k-on/mio.jpg","votes":[{}]},{"name":"mugi","thumbnail":"/images/anime/k-on/mugi.jpg","votes":[{}]},{"name":"ritsu","thumbnail":"/images/anime/k-on/ritsu.jpg","votes":[{}]},{"name":"yui","thumbnail":"/images/anime/k-on/yui.jpg","votes":[{}]}]},{"id":2}]}  

I am trying to add a new set of information, under the ID 2, like I did for 1, starting with the name. I have tried animeData.table.filter(x => x.id === 2).push({"name": "Bunny Girl Senpai"}); However, there are no errors in the console but nor does the "animeData" var change.

https://stackoverflow.com/questions/66519159/push-new-data-to-array-if-indices-match March 08, 2021 at 01:08AM

没有评论:

发表评论