guest271314 (2019-05-27T19:04:14.000Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```let obj = {otherData: "other data", ...["firstName",
"lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```

`Object.assign()`, spread syntax and `map()`

```let obj = Object.assign({otherData: "other data"}, ...["firstName",
"lastName"].map(prop => ({[prop]:user.profile[prop]})));```

or the original approach at the OP.


On Mon, May 27, 2019 at 1:44 PM Григорий Карелин <grundiss at gmail.com> wrote:

> > Is the expected result for ```obj``` to be defined as a variable and
> ```firstName``` and ```lastName``` to not be defined as variables?
> Exactly
>
> As you mentioned above, we may use default value while destructuring to
> achieve the same result, but it looks quite unobvious and creates extra
> variables
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190527/37cb57e5/attachment.html>
guest271314 at gmail.com (2019-05-27T20:50:42.185Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```
let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};
```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```
let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"]
            .map(prop => ({[prop]:user.profile[prop]})));
```

A function using ```Object.assign()```, ```Object.entries()```, ```filter()```, ```in```, ```map()``` which expects first parameter to be the source input object and second parameter to be an object containing new properties and values to be set and properties to be filtered from input object at first parameter where the values are initially set to ```undefined```

```
const filterProps = (o, {...props} = {}) => Object.assign(props, ...Object.entries(o).filter(([key]) => key in props)
                      .map(([key, value]) => ({[key]:value})));
let obj = filterProps(user.profile, {otherData:"other data", firstName:void 0 /* , lastName: void 0 */});
```

or the original approach at the OP

```const obj = {firstName: user.profile.firstName, lastName: user.profile.lastName, otherData: 'other data'};```

which ultimately uses less code; where the proposal of using ```from``` which assigns the properties and values to the target object is not implemented.
guest271314 at gmail.com (2019-05-27T20:50:14.491Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```
let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};
```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```
let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));
```

A function using ```Object.assign()```, ```Object.entries()```, ```filter()```, ```in```, ```map()``` which expects first parameter to be the source input object and second parameter to be an object containing new properties and values to be set and properties to be filtered from input object at first parameter where the values are initially set to ```undefined```

```
const filterProps = (o, {...props} = {}) => Object.assign(props, ...Object.entries(o).filter(([key]) => key in props)
                      .map(([key, value]) => ({[key]:value})));
let obj = filterProps(user.profile, {otherData:"other data", firstName:void 0 /* , lastName: void 0 */});
```

or the original approach at the OP

```const obj = {firstName: user.profile.firstName, lastName: user.profile.lastName, otherData: 'other data'};```

which ultimately uses less code; where the proposal of using ```from``` which assigns the properties and values to the target object is not implemented.
guest271314 at gmail.com (2019-05-27T19:53:11.282Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```
let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};
```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```
let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));
```

A function using ```Object.assign()```, ```Object.entries()```, ```filter()```, ```in```, ```map()``` which expects first parameter to be the source input object and second parameter to be an object containing new properties and values to be set and properties to be filtered from input object at first parameter where the values are initially set to ```undefined```

```
const filterProps = (o, {...props} = {}) => Object.assign(props, ...Object.entries(o).filter(([key]) => key in props).map(([key, value]) => ({[key]:value})));
let obj = filterProps(user.profile, {otherData:"other data", firstName:void 0 /* , lastName: void 0 */});
```

or the original approach at the OP

```const obj = {firstName: user.profile.firstName, lastName: user.profile.lastName, otherData: 'other data'};```

which ultimately uses less code; where the proposal of using ```from``` which assigns the properties and values to the target object is not implemented.
guest271314 at gmail.com (2019-05-27T19:50:59.005Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```
let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};
```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```
let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));
```

A function using ```Object.assign()```, ```Object.entries()```, ```filter()```, ```in```, ```map()``` which expects first parameter to be the source input object and second parameter to be an object containing new properties and values to be set and properties to be filtered from input object at first parameter where the values are initially set to ```undefined```

```
const filterProps = (o, {...props} = {}) => Object.assign(props, ...Object.entries(o).filter(([key]) => key in props).map(([key, value]) => ({[key]:value})));
let obj = filterProps(user.profile, {otherData:"other data", firstName:void 0 /* , lastName: void 0 */});
```

or the original approach at the OP.
guest271314 at gmail.com (2019-05-27T19:50:26.661Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```
let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};
```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```
let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));
```

A function using ```Object.assign()```, ```Object.entries()```, `filter()```, ```in```, ```map()` which expects first parameter to be the source input object and second parameter to be an object containing new properties and values to be set and properties to be filtered from input object at first parameter where the values are initially set to ```undefined```

```
const filterProps = (o, {...props} = {}) => Object.assign(props, ...Object.entries(o).filter(([key]) => key in props).map(([key, value]) => ({[key]:value})));
let obj = filterProps(user.profile, {otherData:"other data", firstName:void 0 /* , lastName: void 0 */});
```

or the original approach at the OP.
guest271314 at gmail.com (2019-05-27T19:46:53.249Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));```

A function 

```
const filterProps = (o, {...props} = {}) => Object.assign(props, ...Object.entries(o).filter(([key]) => key in props).map(([key, value]) => ({[key]:value})));
let obj = filterProps(user.profile, {otherData:"other data", firstName:void 0});
```

or the original approach at the OP.
guest271314 at gmail.com (2019-05-27T19:09:10.490Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```

```Object.assign()```, spread syntax, ```map()``` and computed property name

```let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));```

or the original approach at the OP.
guest271314 at gmail.com (2019-05-27T19:06:58.367Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```let obj = {otherData: "other data", ...["firstName","lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```

```Object.assign()```, spread syntax and ```map()```

```let obj = Object.assign({otherData: "other data"}, ...["firstName","lastName"].map(prop => ({[prop]:user.profile[prop]})));```

or the original approach at the OP.
guest271314 at gmail.com (2019-05-27T19:06:25.667Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```let obj = {otherData: "other data", ...["firstName",
"lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```

```Object.assign()```, spread syntax and ```map()```

```let obj = Object.assign({otherData: "other data"}, ...["firstName",
"lastName"].map(prop => ({[prop]:user.profile[prop]})));```

or the original approach at the OP.
guest271314 at gmail.com (2019-05-27T19:06:02.838Z)
To use destructuring assignment and not create additional variables you can
assign the value of target to a previously defined object

```
let obj = {otherData: "other data"};
({firstName:obj.firstName, lastName:obj.lastName} = user.profile);
```

Alternatively there are various approaches which can be used to get only
specific properties from an abject and set those properties and values at a
new object without using destructing assignment.

Using object rest and ```reduce()```

```let obj = {otherData: "other data", ...["firstName",
"lastName"].reduce((o, prop) => (o[prop] = user.profile[prop], o), {})};```

using `Object.assign()`, spread syntax and `map()`

```let obj = Object.assign({otherData: "other data"}, ...["firstName",
"lastName"].map(prop => ({[prop]:user.profile[prop]})));```

or the original approach at the OP.