1

Let's say you have some JavaScript code that is receiving an object that has an '@' symbol as the first character of the attribute name. How can you access that attribute?

Example:

    var data = { 
        id: 1, 
        msg: "blah blah blah", 
        '@timestamp': "2023-03-28T23:08:03Z" 
    };

I know data.id and data.msg work, but how can I access the data.@timestamp attribute?

I have tried data.@timestamp, and I get "Uncaught SyntaxError: Invalid or unexpected token". I have also tried data.'@timestamp' and that didn't work, as well as data.\@timestamp, and various other permutations attempting to somehow quote the @ symbol.

Is this even possible?

(Note: Renaming the attribute to remove the '@' symbol is not easily possible, because I will be receiving this data from a back-end API.)

m0j0
  • 3,484
  • 5
  • 28
  • 33

0 Answers0