I am trying to delete multiple computed properties from an object at once using destructuring. Something like this
const a = {b: 1, c: 2 , d: 3};
const forbiddenKeys = [ "b", "c"]; // pretend this is computed
const { ...forbiddenKeys, ...rest } = a; // gives "Uncaught SyntaxError: Rest element must be last element"
My plan was to use the rest
variable after these operations to get the rest of the object that is not contained in forbiddenKeys
. Is there a way to do this so that it works like the "Rest in object destructuring" section here? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Computed_object_property_names_and_destructuring