解构和重命名属性 [英] Destructuring and rename property

查看:51
本文介绍了解构和重命名属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const a = {
 b: {
  c: 'Hi!'
 }
};

const { b: { c } } = a;

在这种情况下可以重命名 b 吗?我想要获取 c 并重命名 b.

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

推荐答案

您可以通过重命名进行解构,并采用相同的属性进行解构.

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

这篇关于解构和重命名属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆