l00*_*00k 5 javascript destructuring
我有数组(API 响应):
let arr = [
{ '@type': 'Something', data: 1234 },
{ '@type': 'Something', data: 3214 },
]
Run Code Online (Sandbox Code Playgroud)
是否可以使用那些“@”前缀字段来解构元素?
for (const { data, ??? @type } of arr) {}
Run Code Online (Sandbox Code Playgroud)
您可以采用计算属性和新变量名称。
let arr = [{ '@type': 'Something', data: 1234 }, { '@type': 'Something', data: 3214 }];
for (const { data, ['@type']: renamed } of arr) {
console.log(renamed);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
187 次 |
最近记录: |