2

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?

  • Don't use reserved characters in field names/ids? Joking, kind of. Your answer is already below... just saying, if possible, avoid the problem by following standards. – TCooper Aug 19 '20 at 23:31
  • @TCooper I didn't write the API that I'm retrieving data from :p – Sean Hufnagel Aug 20 '20 at 15:44
  • Wow, clearly only half read that first part... amazing what selective attention can do. Tell those API devs to follow standards ;) – TCooper Aug 20 '20 at 17:05

2 Answers2

5

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

snak
  • 6,483
  • 3
  • 23
  • 33
  • yep thats the trick thank you! I honestly tried bracket notation but haven't used it in a while and forgot that it required quotes.. – Sean Hufnagel Aug 19 '20 at 23:40
1

Try using bracket notation instead:

item['@timestamp']

Hopefully that helps!

Alexander Staroselsky
  • 37,209
  • 15
  • 79
  • 91