Bada
Bada's Coding

Bada's Coding

Destructuring a Nested Object

Bada's photo
Bada
·Aug 2, 2022·

1 min read

Below is the example.

const obj = { k1: { k11: 1 } };

const {
  k1: { k11 },
} = obj;

// console.log(k1); // Error: k1 is not defined
console.log(k11); // 1

This can be useful when you want to change 'e.target.value' into 'value' in event handling.

Below is the example.

 
Share this