Destructuring and rename property

后端 未结 2 1862
渐次进展
渐次进展 2021-01-01 19:55
const a = {
 b: {
  c: \'Hi!\'
 }
};

const { b: { c } } = a;

Is it possible rename b in this case? I want get c and also

2条回答
  •  一整个雨季
    2021-01-01 20:27

    You can destructure the same property multiple times, onto different targets:

    const { b: {c}, b: d } = a;
    

    This assigns a.b.c to c and a.b to d.

提交回复
热议问题