-1

I have a web page that shows a list of books and when the user selects one of them it shows the details of the book, including a button to like the book. All that information is stored in JSON database and the likes are stored in an array with the Id and name of the user who liked it. I am looking to be able to add or remove elements to that array using the HTTP method PATCH. Currently, I have this code, but it adds the elements outside the array. What is the correct way to reach the array?

const configurationObj = {
    method: "PATCH",
    headers: {
        "Content-Type": "application/json",
        Accept: "application/json"
    },
    body: JSON.stringify(users)
};
fetch(`http://localhost:3000/books/${book.id}`, configurationObj)
    .then (response => response.json())

The database is something like this: [1]: https://i.stack.imgur.com/4jUOB.png

  • 1
    `x.users` is the array (where `x` is the variable holding the response which is no longer anything to do with JSON after you've parsed it using `response.json()` - it's just a regular javascript object now) – Bravo May 09 '22 at 06:06

0 Answers0