我有数组(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);
}