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

后端 未结 30 2281
日久生厌
日久生厌 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:18

    First thing check the type like below:

    console.log(typeof config);
    

    If the command above prints object then it is very easy you just use the bracket notation. Bracket notation can be quite useful if you want to search for a property’s values dynamically.

    Execute the command below:

    console.log(config[col_id_3]);
    

    If it a string you need to parse in object first. To do that you need to execute the command below:

    var object = JSON.parse(config);
    

    And after that use bracket notation to access the property like below:

    console.log(object[col_id_3]);
    

提交回复
热议问题