Destructuring same key name

A property can be unpacked from an object and assigned to a variable with a different name than the object property.

response1 = {
  data : {
     username : 'john'
  },
  status: '200'
};

response2 = {
  data : {
    obj : {
      product : "Car"
    }
  },
  status: '404'
}

const { data } = response1;
const { data : obj } = response2;

console.log(data);
console.log(JSON.stringify(obj));

 

Destructuring same key name

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.