-3

After fetching a json object from an external API I get the following as an example:

id: 1
name: john
email: something@example.com
3a5411a124378534906a883a0c5ccda5724175eb: USA

So, in JavaScript I can easily access: object.id, object.name, etc.

However, object.3a5411a124378534906a883a0c5ccda5724175eb throws the error:

Identifier directly after number

How do deal with a situation like that? Or, in other words, how can I get the value of USA?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
T. Short
  • 3,481
  • 14
  • 30

2 Answers2

1

use

object["3a5411a124378534906a883a0c5ccda5724175eb"];
Kudratillo
  • 190
  • 11
1

Use the for-in loop on object to access all the properties of objects as follows event the properties like you mention,

var obj = {
id: 1,
name: 'john',
email: 'something@example.com',
'3a5411a124378534906a883a0c5ccda5724175eb': 'USA'
}
for(var prop in obj){
//do the stuff here what you want for each properties
    console.log(obj[prop]);
}
Naim Sulejmani
  • 1,130
  • 9
  • 10