Currently delving into the world of web development. Here I am, working on my first express server and facing a little challenge:
I am trying to update multiple values of an object within an array using app.patch, but struggling with the syntax.
While my current code gets the job done, I believe there might be a more elegant solution out there. Here's what I have so far:
app.patch("/tabak/:id", (req, res) => {
const { id } = req.params;
const { name, brand, flavour, score, desc } = req.body;
const foundTabak = tabakArray.find(t => t.id === id);
foundTabak.name = name;
foundTabak.brand = brand;
foundTabak.flavour = flavour;
foundTabak.score = score;
foundTabak.desc = desc;
res.redirect("/tabak");
});
If anyone knows how to condense the five lines where foundTabak.x = x into one line, I would appreciate your input!
Thank you for your assistance!