In JavaScript/Typescript,
What is the short version to destructure and then assign in a new object like so :
const payload: MyPayload = { a: 1, b: 2, c: 3, d: 4, e: 5 }
// Destruct
const { a, c, e } = payload;
// New Obj
const newPayload = {
a, c, e
};
You could take a destructuring assignment with the object and short hand properties for a new object.
const
getParts = ({ a, c, e }) => ({ a, c, e }),
payload = { a: 1, b: 2, c: 3, d: 4, e: 5 },
parts = getParts(payload);
console.log(parts);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With