如何从JS对象

时间:2018-03-26 08:51:43

标签: javascript json

我目前正在运行console.log这样的变量:

console.log(runnable);

当我查看控制台时,我看到了这些数据:

enter image description here

我想访问runnable.err键,但控制台会返回undefined

在此之后我尝试使用console.log(JSON.stringify(runnable));但是我收到了以下错误:

TypeError: Converting circular structure to JSON

在研究如何转换循环结构时,我能找到的是在不包含循环数据的情况下安全地解析数据的方法。有什么方法可以访问这些数据吗?不幸的是,我无法改变数据。

由于

1 个答案:

答案 0 :(得分:2)

我认为这里发生的事情是runnable在您调用.err时没有console.log(runnable)属性,但稍后会添加.err属性。

在对象上使用console.log()可能会表现得很奇怪(显示对象的当前状态而不是记录时的状态)。见console.log() shows the changed value of a variable before the value actually changes

要测试该假设,请尝试更改

console.log(runnable.err);

setTimeout(function() {
    console.log(runnable.err);
}, 1000);

并查看它是否不再是undefined

相关问题