1

I have the following object:

this

If I try to get the value from it by using let result = object.3h I get the following error

this

error: `Parsing error: Identifier directly after number`.
tehsis
  • 1,602
  • 2
  • 11
  • 15
Andrei Bunea
  • 111
  • 10

2 Answers2

1

you need to use bracket notation

correct

object["3h"]

incorrect

object.3h

    const object = { "3h": 0.44 }
    console.log(object["3h"])
MRsabs
  • 85
  • 3
1

Identifiers in Javascript can’t start with a number (You can check the exact rules at the link provided.

When dealing with object properties, you can use string literals for defining properties that won’t follow this rule (Which might also happen when dealing with JSON objects)

In order to access this properties you need to use a property accessor

On your case:

day.rain[‘3h’]
tehsis
  • 1,602
  • 2
  • 11
  • 15