Destructuring and rename property

后端 未结 2 1869
渐次进展
渐次进展 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:29

    You could destructure with a renaming and take the same property for destructuring.

    const a = { b: { c: 'Hi!' } };
    const { b: formerB, b: { c } } = a;
    
    console.log(formerB)
    console.log(c);

提交回复
热议问题