JavaScript 解构包含特殊字符字段的对象

JavaScript destructuring object containing fields with special characters

我有数组(API 响应):

let arr = [
    { '@type': 'Something', data: 1234 },
    { '@type': 'Something', data: 3214 },
]

是否可以解构带有“@”前缀字段的元素?

for (const { data, ??? @type } of arr) {}

你可以取一个 computed property 和一个新的变量名。

let arr = [{ '@type': 'Something', data: 1234 }, { '@type': 'Something', data: 3214 }];

for (const { data, ['@type']: renamed } of arr) {
    console.log(renamed);
}