Destructuring same key name

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));

 

Write a Reply or Comment

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