for文はほぼもう使わないので、よっぽどの事がない限りそこまで意識して使う必要はないかも。
後、if文の嵐は疲れるので、複数の条件があれば先にチェックして順々に抜け出ていくとif文のネストが起きなくて読むのが楽になります。
function logincheck() {
const id = document.getElementById("id").value;
const pw = document.getElementById("pas").value;
if (id === "" && pw === "") {
alert("IDとパスワードは必須入力です");
return;
}
if (id === "") {
alert("IDは必須入力です");
return;
}
if (pw === "") {
alert("パスワードは必須入力です");
return;
}
//ユーザー仮ナンバー
const usernum = [
["ss", "2222"],
["df", "4444"],
["we", "5555"],
];
const found = usernum.find(
([idFromTable, passwordFromTable]) =>
idFromTable === id && passwordFromTable === pw
);
if(!found){
alert("IDとパスワードが一致しません");
return;
}
window.location.href = "html トップ画面.html";
}
Like!