D
D
Dill52021-03-12 08:28:27
JavaScript
Dill5, 2021-03-12 08:28:27

Why does Express JS change the name of an object's key?

Hello. The question is the following, when sending POST data to the server on node js with a request, namely an object in which one of the values ​​is an array, but in request.body I get this object with a changed key only for the array: it was "tags" -> it became "tags []".
Send code:

$.ajax({
      type: "POST",
      url: "/admin/create",
      data: data,
      success: (response) => {
        console.log("success", response);
        if(response.success) {
          clearInputs();
          getAllProjects();
        }
      },
      error: (error) => {
        console.log("error", error);
      }
    });

Receipt code:
adminRouter.post("/create", projectController.create);

exports.create = function(request, response) {
  if(!request.body) return response.sendStatus(400);
  const { id, ...data } = request.body;
  console.log(request.body);
        response.send(data);
};

In the screenshot, the data that goes out and the data that comes in. Also in console.log on the server in request.body is the same.
604afbbc2d6a5024689829.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question