gpt4 book ai didi

javascript - 如何在 TypeScript 中打破 ForEach 循环

转载 作者:太空狗 更新时间:2023-10-29 17:02:20 24 4
gpt4 key购买 nike

我有下面的代码,在某些情况下我无法打破循环。

function isVoteTally(): boolean {
let count = false;
this.tab.committee.ratings.forEach((element) => {
const _fo = this.isEmptyOrNull(element.ratings.finalOutcome.finaloutlook);
const _foreign = this.isEmptyOrNull(element.ratings.finalOutcome.foreign);
const _local = this.isEmptyOrNull(element.ratings.finalOutcome.local);
const _tally =
element.ratings.finalOutcome.voteTally.maj +
element.ratings.finalOutcome.voteTally.dis;

if (_fo == false && _foreign == false && _local == false) {
if (_tally > 0) {
return (count = false); // ⭐
}
} else {
if (_tally < 0) {
return (count = false); // ⭐
}
}
});
return count;
}

在星标区域,我想破解代码并返回 bool 值,但我做不到。怎么做到的?

最佳答案

this.tab.committee.ratings.forEach 不是运算符。

Typescript 允许编写更具可读性的代码。

按如下方式使用 for 循环:

for (let a of this.tab.committee.ratings) {
if (something_wrong) break;
}

附注忘记 Angular 中的“使用 jQuery 编码”。它就是行不通。

关于javascript - 如何在 TypeScript 中打破 ForEach 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51747397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com