You can't do it in a single step, you have to create the object first. Then you can assign to its properties via destructuring:
const response = {};
({_id: response.id, email: response.email} = someVariable);
json.res(response);
const someVariable = {
_id: 42,
email: "[email protected]",
};
const response = {};
({_id: response.id, email: response.email} = someVariable);
console.log(response);
(Note the () around the assignment. That's so the parser doesn't think the { starts a block.)
As you can see, it doesn't do you much (if any) good over something like:
const response = {
id: someVariable._id,
email: someVariable.email,
};
res.json(response);
The only thing it really has going for it is that you only reference someVariable once, which could be handy if it's not a simple variable reference (like a function call; but countering that, you could just save the result to a variable).