i use Mongoose to get my data from my database with this get function.
router.get("/:id", async (req, res)=> {
const products = await Product.findOne({slug: req.params.id});
if (products) {
res.send(products);
} else {
res.status(404).send({message:"product not found"})
}
});
The output seems to be an object. However i need a array instead, because i use the slice() method in my further code.
What i tried: var ready = Object.keys(products).map((key) => [Number(key), products[key]]);
Is there any function i could use to make an array instead of the object or another mongoose function for getting an array?