Answer the question
In order to leave comments, you need to log in
Why does .find in mongoose return not an array?
I have a collection, and before sending it to the client, I need to remove the item property from each element, but for some reason ide says that items does not have lenght, and the for loop is simply skipped
const items = await productModel.find()
console.log(items)
for(let i = 0; i < items.lenght; i++){
console.log(items[i])
delete items[i].keys
console.log(items[i])
}
res.status(200).json({items: items})
Answer the question
In order to leave comments, you need to log in
In passing, I wrote nonsense in a hurry, so I edit:
You cannot have a lenght property - because there is no such thing in nature =)) right - length
This is a common mistake for beginners!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question