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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With