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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.