javascript - 如何在打字稿中将for循环转换为foreach
问题描述
有没有办法将下面的 for 循环转换为 forEach?我检查了 SO 中的解决方案,但找不到与我相关的任何内容。
private wasFormChanged(currentValue) {
const fields = ['givenName', 'familyName', 'email', 'username'];
for (let i = 0; i < fields.length; i++) {
const fieldName = fields[i];
if (this.user[fieldName] !== currentValue[fieldName]) {
this.disableButton = false;
return;
}
}
this.disableButton = true;
}
解决方案
推荐阅读
- php - 如何在不删除旧数据的情况下向数据库列添加新值
- angular - Angular 6,如何获取“onSelectionChange”dom事件的目标元素?
- django - NoReverseMatch 在 /products/ ,“产品”不是注册的命名空间
- angular - 星云企业主题不能开箱即用
- ios - Swift 将不同类型组合成一个数组来显示 UITableView 的数据
- android - 如何在 android (editText) 中编写新的材料设计文本字段
- c++ - GNU GCC 会跟踪以前使用箭头运算符取消引用的对象吗?
- c++ - 向量索引不会在 C++ 中环绕吗?解决方法是什么?
- applescript - 使用苹果脚本在文件夹中查找文件名
- r - 创建等级或索引向量