0

i have below json data

"D3" : {
                "D3-00" : {
                    "DATETIME" : "01-11-2022 17:00:25",
                    "MECHANISM" : "",
                    "B2" : {
                        "DATETIME" : "01-11-2022 00:00:00",
                        "MECHANISM" : "Auto"
                    },
                            }
        }

How do i traverse inside D3.D3-00.DATETIME currently i am getting error as NaN

  • `data.D3["D3-00"].DATETIME` – VLAZ Nov 09 '22 at 07:01
  • _"currently i am getting error as NaN"_ - probably because of the _subtraction_ operation you wrote, I suppose. – CBroe Nov 09 '22 at 07:01
  • @VLAZ minus the dot before the square brackets though. – CBroe Nov 09 '22 at 07:02
  • @VLAZ thanks for this data.D3["D3-00"].DATETIME – Aksheet-Goku Nov 09 '22 at 07:05
  • 1
    @CBroe quite amusingly, OP's code manages to avoid being a syntax error *just by a hair*. `00.DATETIME` is valid because `00` is treated as an *octal* literal, and thus `.DATETIME` is trying to access a non-existant property from the number, producing `undefined`. However, if it was almost anything else, it'd fail: `42.DATETIME` is not valid because the dot is parsed as decimal separator. And `FOO.DATETIME` would fail because `FOO` is not defined. While something like `1A.DATETIME` would fail because it's not a valid identifier. – VLAZ Nov 09 '22 at 07:06

0 Answers0