【发布时间】:2017-10-26 13:56:09
【问题描述】:
这个问题没有任何疑问或问题。显然,我似乎在 chrome 控制台上偶然发现了一个错误,
我使用这个代码:
console.log("Before: ", this.selectedScorecard.scorecard_attributes);
let attribute = this.selectedScorecard.scorecard_attributes.find(item => item.id === null || item.id === undefined)
if(attribute) {
let length = this.selectedScorecard.scorecard_attributes.length;
this.selectedScorecard.scorecard_attributes.splice(length-1, 1);
console.log("After: ", this.selectedScorecard.scorecard_attributes);
}
好的,所以属性是一个数组,它最初是一个长度为 2 的数组。 现在我从数组中拼接一个项目并在拼接前后打印它的值。
在数组之前的 sn-p 的 chrome 控制台中,它显示 (2) 指示长度为 2,但在数组本身中,它显示长度为 1,并且在“数组控制台前”中也只有一项 而事情显然在“控制台之后”中符合预期 我附上一张图片以便更好地理解
我很好奇,有人知道吗?有没有人遇到过这种情况,还是只有我一个人注意到它?
【问题讨论】:
-
如果您不想更改对象,则需要对其进行深度复制。
-
要解决这个问题:
console.log("Before: ", JSON.parse(JSON.stringify(this.selectedScorecard.scorecard_attributes))); -
欢迎来到副作用的世界。
-
悬停在每一行中的
[i]。它告诉您该值是在您扩展行时评估的。
标签: javascript ecmascript-6 google-chrome-devtools web-inspector