I have array (API response):
let arr = [
{ '@type': 'Something', data: 1234 },
{ '@type': 'Something', data: 3214 },
]
Is it possible to destructure elements with those '@' prefixed fields?
for (const { data, ??? @type } of arr) {}
You could take a computed property and a new variable name.
let arr = [{ '@type': 'Something', data: 1234 }, { '@type': 'Something', data: 3214 }]; for (const { data, ['@type']: renamed } of arr) { console.log(renamed); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.