Reputation: 678
I am using Node.js and this is my response of my routes.
I want to REMOVE the objects that have the value of "existence":false
and output the object that has value of "existence":true"
This is my code so far.
schedule.get('/conference/schedule_participants/:circle/:confUid/:schedId', function(req, res) {
if(req.schedId){
getParticipants( req.params, function(contacts){
results.contacts=contacts;
res.send('response('+JSON.stringify(results.contacts)+')');
});
} else{
res.send('response('+JSON.stringify(results.contacts)+')');
}
});
Upvotes: 0
Views: 41
Reputation: 11725
You can use Array.prototype.filter
:
var filtered = results.contacts.filter(function(c) {
return c.existence;
});
res.send('response(' +JSON.stringify(filtered) + ')');
Upvotes: 2
Reputation: 2872
var filtered = results.contacts.filter(function(contact) {
return contact.existence;
});
Upvotes: 1