1

I am creating a route in node.js

and this is my code:

schedule.get('/conference/schedule_participants/:circle/:schedId', function(req, res) {
  if(req.schedId){
      getParticipants( req.params, function(contacts){
        results.contacts=contacts;
          res.json(results);
      }); 

  }else{
        res.json(results);
  }
});

the output in my browser is like this :

"schedSetting":{
"id":59,
"sched_date":"2016-03-03 09:03:00",
"agenda":"meeting",

},
"contacts":[
{
"id":218,
"accountcode":"",
"extentype":0,

},

}
]
}

How can i remove the schedSetting array so that my output will only be the contacts array like this :

"contacts":[
    {
    "id":218,
    "accountcode":"",
    "extentype":0,

    },

    }
    ]

Thanks :)

2
  • what about delete(results['schedSetting']) ? Commented Mar 3, 2016 at 8:24
  • What is inside variale results server side in the first place? Commented Mar 3, 2016 at 8:25

2 Answers 2

2

You can send the contacts instead of results variable:

res.json(contacts);

Full code:

schedule.get('/conference/schedule_participants/:circle/:schedId', function(req, res) {
  if(req.schedId){
      getParticipants( req.params, function(contacts){
        results.contacts=contacts;
          res.json(contacts);
      }); 

  }else{
        res.json(results);
  }
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can use:

delete myObject.myKey; 
// or 
delete myObject['myKey']; 
// or 
var myProp = "myKey"; 
delete myObject[myProp]

If you interest in reading about it Understanding delete

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.