Answer the question
In order to leave comments, you need to log in
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);
}
});
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);
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question