how to escape @ in javascript or how to retrieve data from a field containing @

113 Views Asked by At

I am retrieving data from an API and one of the fields in the object it returns is @timestamp. When ever I try to parse this data like item.@timestamp javascript throws an error because the @ symbol is reserved as a decorator. How can I retrieve data from a field that is using a reserved character?

2

There are 2 best solutions below

1
snak On BEST ANSWER

Use item['@timestamp'] instead of item.@timestamp.

0
Alexander Staroselsky On

Try using bracket notation instead:

item['@timestamp']

Hopefully that helps!