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

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

    The property you're trying to access might not exist yet. Console.log works because it executes after a small delay, but that isn't the case for the rest of your code. Try this:

    var a = config.col_id_3;    //undefined
    
    setTimeout(function()
    {
        var a = config.col_id_3;    //voila!
    
    }, 100);
    

提交回复
热议问题