How to destructure object and make alias for keys name

Let say you have object that look like this:

const userData={firstName:’John’,lastName:’Doe’,country:’Ireland’}

Then you want to destructure this object and change country key name with nationality, here how to do that

let {firstName,lastNa…


This content originally appeared on DEV Community and was authored by Heru Hartanto

Let say you have object that look like this:

const userData={firstName:'John',lastName:'Doe',country:'Ireland'}

Then you want to destructure this object and change country key name with nationality, here how to do that

let {firstName,lastName,country:nationality} = userData
    /*
        firstName
        'John'
        lastName
        'Doe'
        country
        Uncaught ReferenceError: country is not defined 
--> because we don't declare country variable
        nationality
        'Ireland'
    */


This content originally appeared on DEV Community and was authored by Heru Hartanto


Print Share Comment Cite Upload Translate Updates
APA

Heru Hartanto | Sciencx (2021-11-19T14:16:03+00:00) How to destructure object and make alias for keys name. Retrieved from https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/

MLA
" » How to destructure object and make alias for keys name." Heru Hartanto | Sciencx - Friday November 19, 2021, https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/
HARVARD
Heru Hartanto | Sciencx Friday November 19, 2021 » How to destructure object and make alias for keys name., viewed ,<https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/>
VANCOUVER
Heru Hartanto | Sciencx - » How to destructure object and make alias for keys name. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/
CHICAGO
" » How to destructure object and make alias for keys name." Heru Hartanto | Sciencx - Accessed . https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/
IEEE
" » How to destructure object and make alias for keys name." Heru Hartanto | Sciencx [Online]. Available: https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/. [Accessed: ]
rf:citation
» How to destructure object and make alias for keys name | Heru Hartanto | Sciencx | https://www.scien.cx/2021/11/19/how-to-destructure-object-and-make-alias-for-keys-name/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.