IMO is the easiest way to accomplish what you are looking for:
let { prop1, prop2, prop3 } = someObject; let data = { prop1, prop2, prop3 };
Basically, collapse in variables, and then use the abbreviated initializer value to create a new object. No need for Object.assign
I think this is the most readable way, anyway. Here you can select the exact details from someObject that you want. If you have an existing object, you just want to combine the details, do something like this:
let { prop1, prop2, prop3 } = someObject; let data = Object.assign(otherObject, { prop1, prop2, prop3 });
Another, possibly cleaner way to write:
let { prop1, prop2, prop3 } = someObject; let newObject = { prop1, prop2, prop3 };
I use this for POST requests, where I need only a few pieces of discrete data. But I agree that there must be one liner for this.
Zfalen Jun 23 '17 at 18:04 on 2017-06-23 18:04
source share