Skip to content

Attributing a destructured object to an object to spread it, is it possible? #4865

Closed Answered by aduh95
j3rrb asked this question in Q&A
Discussion options

You must be logged in to vote

Here's how you can do that:

const obj = {a: 1, b: 2, c: 3};
const { a, b } = obj;
const newObj = { a, b };

or

const obj = {a: 1, b: 2, c: 3};
const newObj = { a: obj.a, b: obj.b };

Note that Node.js doesn't have control over JavaScript the language, discussion over the language spec is happening in https://github.com/tc39/proposals.

Replies: 0 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@aaarichter
Comment options

Answer selected by avivkeller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants