J
J
judywb2022-03-28 13:43:28
JavaScript
judywb, 2022-03-28 13:43:28

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

1 answer(s)
F
FIREguardSPB, 2022-03-28
@judywb

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 question

Ask a Question

731 491 924 answers to any question