I have a list of saved items in a Mongo collection, I'd like to know how to filter the original array. Follow the code
api.filtra = function (req, res) {
model.find()
.then(function(itens) {
for(i = 0; i < itens.length; i++)
console.log(itens[i].criterio);
res.json(itens);
console.log("testeA");
var filtrado = itens.filter(
itens, {"genero": "0"}
);
console.log("testeB");
console.log(filtrado);
}, function (error) {
console.log(error);
res.sendStatus(500);
});
}
The problem with this code is that it crashes when it's time to run "itens.filter", the last thing it displays on the console is "testA" Home What I would like to do is, for example, say I have people in this array, pass as a parameter via url the age, more or less like '/ v1 / people / age / x' where x is the age chosen by the user, and so just send the list to the browser with people who already meet this criteria. Home I hope I have been able to explain my doubts well, but if you have been confused tell me that I will try to rephrase my question. Home Thank you all right away.