es6 object destructuring, assign into new object

591 views Asked by At

new to es6 here. is there any way to shorten this code with es6 features? i'm trying to destructure from an object and put those pulled properties into a new object.

    const { Height, Width, Location, MapAttachmentTypes, 
ZoomLevelAdjustment, CustomPushPins, CenterPushpinStyle, ScaleFactor } = args;
        const body = {
          Height,
          Width,
          Location,
          MapAttachmentTypes,
          ZoomLevelAdjustment,
          CustomPushPins,
          CenterPushpinStyle,
          ScaleFactor
        };

I tried this, but it didn't work:

const  body = { Height, Width, Location, MapAttachmentTypes, ZoomLevelAdjustment, CustomPushPins, CenterPushpinStyle, ScaleFactor } = args;
1

There are 1 answers

6
Walle Cyril On
    // new syntax
    const body = {
        ...args
    };
    // es5
    const body = Object.assign({}, args);