New Object from Object extraction

# Felipe Nascimento de Moura (7 years ago)

So, let's say you want a new object containing only some of the properties from another object.

For example, if I have the Object1 like this: o1 = { a: 1, b: 2, c: 3, d: 4, e: 5 }

And I want another object containing Object1's b, c, and e.

I could:

o2 = {...o1} // a full copy of o1 o2 = { b: o1.b, c: o1.c, e: o1.e} // works, but is "boring" :p let {b, c, e} = o // will create variables, instead of an o2 with the properties

I think we could have a shorthand syntax that would be a combination of the syntaxes we already have. Something like:

o2 = {

}

Or, perhaps:

o2 = {b, c, e}...o1

Is there another way we can already accomplish it with a modern syntax?

. [ ]s

--

Felipe N. Moura Web Developer, Google Developer Expert developers.google.com/experts/people/felipe-moura, Founder of

BrazilJS braziljs.org and Nasc nasc.io.

Website: felipenmoura.com / nasc.io Twitter: @felipenmoura twitter.com/felipenmoura

Facebook: fb.com/felipenmoura LinkedIn: goo.gl/qGmq

Changing the world is the least I expect from myself!

# T.J. Crowder (7 years ago)

On Sun, Mar 18, 2018 at 7:06 PM, Felipe Nascimento de Moura <felipenmoura at gmail.com> wrote:

So, let's say you want a new object containing only some of the properties from another object.

This has come up repeatedly, including very recently (most recent post today):

esdiscuss.org/topic/expanding-object-shorthand

esdiscuss.org/topic/destructuring-into-object

I believe the most complete proposal is here:

rtm/js-pick-notation

-- T.J. Crowder

# Felipe Nascimento de Moura (7 years ago)

interesting.

good to known there are proposals for that :)

tks

[ ]s

--

Felipe N. Moura Web Developer, Google Developer Expert developers.google.com/experts/people/felipe-moura, Founder of

BrazilJS braziljs.org and Nasc nasc.io.

Website: felipenmoura.com / nasc.io Twitter: @felipenmoura twitter.com/felipenmoura

Facebook: fb.com/felipenmoura LinkedIn: goo.gl/qGmq

Changing the world is the least I expect from myself!