5

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) {}
l00k
  • 1,525
  • 1
  • 19
  • 29

1 Answers1

6

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);
}
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392