Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Neater way to assign to variable from Object

Is there a neater way to assign the values to objects rather than what I have:

My code:

let val1 = result.data.data.table.val1;
let val2 = result.data.data.table.test.val2;
let val3 = result.data.data.table.val3;
let val4 = result.data.data.table.val4;
let val5 = result.data.data.table.val5;

Is there a neater way to assign this, a one-liner?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think what you’re looking for is destructuring.

let {val1, test: {val2}, val3, val4, val5} = result.data.data.table;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading