首页 > 解决方案 > 如何在打字稿中将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;
}

标签: javascriptangulartypescriptforeach

解决方案


推荐阅读