Advertisement

使用无效变量名进行对象解构

阅读量:

使用invalid variable name作为property names来进行object destructuring

百度翻译此文 有道翻译此文
问 题

Is there anyone who knows whether it's possible to perform object destructuring on a property name that includes spaces? Maybe not, and I've noticed that the JavaScript notation isn't correct, but I can't alter the server's JSON response.

创建一个名为obj1的数据结构。
// 进行解构赋值操作
从obj1中提取名称和年龄属性。
// 其中name属性值为Mr. Smith, 年龄为21岁
该方案能够预期地发挥作用。

However, if I encounter the following object structure, should I be able to use object destructuring?

const obj2 = {{‘my name’: “Mr Jones”, age: 22}}; const {‘myName’, age} = obj

全部评论 (0)

还没有任何评论哟~