Sean Hufnagel
Sean Hufnagel

Reputation: 61

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

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?

Upvotes: 2

Views: 130

Answers (2)

Alexander Staroselsky
Alexander Staroselsky

Reputation: 38767

Try using bracket notation instead:

item['@timestamp']

Hopefully that helps!

Upvotes: 1

snak
snak

Reputation: 6703

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

Upvotes: 5

Related Questions