[英]Nested array filter() functions in typescript - always returns true?
[英]Typescript / Ionic count elements in array returns always 0
我正在编写一个离子应用程序,它通过使用“存储”来存储一些表单条目和一些选项。 现在我想计算选项,但我总是得到零。
我正在使用以下代码:
async getAllEntries()
{
let count = 0;
this.trackingEntries = [];
this.storage.forEach((value, key, index) =>
{
if (key != "Options0" && key != "Options1" && key != "Options2" && key != "Options3" )
{
this.trackingEntries.push(value);
count++;
}
})
console.log(this.trackingEntries);
console.log("Count: " + count);
}
console.log(this.trackingEntries) 返回以下 object:
[
{
"timestamp": "1663677073",
"tracking": [
"6",
"4",
"5",
"6"
]
},
{
"timestamp": "1663677073",
"tracking": [
"2",
"2",
"2",
"2"
]
},
{
"timestamp": "1663677073",
"tracking": [
"2",
"2",
"2",
"2"
]
}
]
但计数变量始终为零。 我怎么解决这个问题?
我通过使用“then”找到了解决方案。
async getAllPottyTrackingEntries() {
this.trackingEntries = [];
this.storage.forEach((value, key, index) => {
if (key != "Options0" && key != "Options1" && key != "Options2" && key != "Options3") {
this.trackingEntries.push(value);
}
}).then(() => {
console.log("Count: " + this.trackingEntries.length)
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.