Can't access object property, even though it shows up in a console log

后端 未结 30 1795
日久生厌
日久生厌 2020-11-22 06:26

Below, you can see the output from these two logs. The first clearly shows the full object with the property I\'m trying to access, but on the very next line of code, I can\

30条回答
  •  难免孤独
    2020-11-22 07:01

    I faced the same problem today. In my case the keys were nested, i.e key1.key2. I split the keys using split() and then used the square bracket notation, which did work for me.

    var data = {
        key1: {
              key2: "some value"
           }
    }
    

    I split the keys and used it like this, data[key1][key2] which did the job for me.

提交回复
热议问题