0

I am using Node.js and this is my response of my routes.

enter image description here

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)+')');
  }
});

2 Answers 2

2

You can use Array.prototype.filter:

var filtered = results.contacts.filter(function(c) {
  return c.existence;
});

res.send('response(' +JSON.stringify(filtered) + ')');
Sign up to request clarification or add additional context in comments.

3 Comments

Hello @Buzinas . I want to remove the object that has the value of "existence":false" and output the object that has value of "existence":true"
@Agent69 that's exactly what I'm doing here ;)
If you don't like the readability, you can change the filter return to return c.existence === true;. But since it's already a boolean, there is absolutely no need for that.
1

Use Array.prototype.filter()

var filtered = results.contacts.filter(function(contact) {
    return contact.existence;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.