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

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

    None of the JSON stringify/parse worked for me.

    formValues.myKey:               undefined
    formValues.myKey with timeout:  content
    

    I wanted the value of formValues.myKey and what did the trick was a setTimeout 0 like in the example below. Hope it helps.

    console.log('formValues.myKey: ',formValues.myKey);
    setTimeout( () => { 
      console.log('formValues.myKey with timeout: ', formValues.myKey);
    }, 0 );
    

提交回复
热议问题