There is a way to pick out sub-properties using desructuring,
but I think it's awful for readability..
const me = { name:'David', family: { wife : { name: 'TBD' }, animal: { name : 'Jess', type: 'dog', }, } } const { family: { wife: { name: wife } } } = me; const { family: { animal: { name: dog } } } = me; // OR const { family } = me; const { wife: { name: wife1 } } = family; const { animal: { name: dog1 } } = family; console.log({ wife1 }); console.log({ dog1 });
Ah, this is cool though!
If you want, you can do all three at once -- though I agree with your point that for readability, there aren't any gains here.
const { name, family: { wife: {name: wife} } , family : { animal : {name: dog } } } = me;
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There is a way to pick out sub-properties using desructuring,
but I think it's awful for readability..
Ah, this is cool though!
If you want, you can do all three at once -- though I agree with your point that for readability, there aren't any gains here.