Renaming Fields when using Object Destructuring.

Subscribe to my newsletter and never miss my upcoming articles

At times, an object may contain one or more properties - but you want to destructure it whilst changing the property name.

Take for instance, some function name does not suit your coding convention, or you already have a variable with that name.

You can rename one of the fields like so:

 const  bioData = {
    name: 'Olusegun',
    profession: 'Software Developer'
 };

const { name: first, profession } = bioData;

first // 'Olusegun'
profession // 'Software Developer'

No Comments Yet