Updating array with fetch put

Hi!

I have a post object on server which contains array of likes

Screenshot 2022-10-25 185831

how do I increase or decrease its length with fetch put method?

export function addLike() {
  fetch(
    "https://nomoreparties.co/v1/" +
      `${cohortId}` +
      "/cards" +
      "/" +
      `cardNumber`,
    {
      method: "PUT",
      headers: apiConfig.headers,
      body: JSON.stringify({
        _id: apiConfig.id,
        likes: likes.push(1),
      }),
    }
  )
    .then((response) => response.json())
    .then((json) => console.log(json));
}

When I call this function I get Uncaught ReferenceError: likes is not defined, but it’s there! The idea was to push one random element to likes array to increase it’s length(likes count)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.