【发布时间】:2021-01-15 02:54:36
【问题描述】:
我创建了需要返回适当长度项目的方法:
@Input() items: any[];
calculateCount(type?: string | string[]): number {
if (typeof type === 'object') {
for (let value of type) {
this.items && this.items.filter((item) => item.type === value).length;
}
//TODO: return sum of values from loop;
}
if (typeof type === 'string') {
return this.items && this.items.filter((item) => item.type === value).length;
}
return this.items && this.items.length;
}
但我需要建议如何从循环中返回值的总和。谢谢
【问题讨论】:
标签: javascript angular typescript for-loop