I'm trying to desctructure an object into another object, I mean taking sub-set of properties from Object A to Object B. I'm doing it like this:
const User = new UserImpl();
User.email = user.email;
User.name = user.name;
User.family_name = user.familyName;
User.password = 'Test!';
User.verify_email = true;
User.email_verified = false;
User.blocked = false;
const {
email,
name,
family_name,
password,
verify_email,
email_verified,
blocked,
connection
} = User;
const res_user = {
email,
name,
family_name,
password,
verify_email,
email_verified,
blocked,
connection
};
return res_user;
but, is there a way to do it using Object.assign() ? or using arrow => function instead of having two variables or doing it in two steps?
Thanks
Object.assign()or object literal spread, but this code isn't really a minimal reproducible example so it's hard to know what would meet your needs. If you're really only copying a subset of properties, can you make your example show this? It will be helpful if your code can be dropped into any IDE and show your issue. As it stands, you haven't definedUserImploruser.const objA = {...commonPart, foo: 'bar'}andconst objB = {...commonPart, bim: 'bam'}?