When registering an email, I need to know if it is not in an array of spam data which cannot be used to register an email. My question is how exactly the function works indexOf
: I send as [email protected] email and if it matches, how come it compares only the left part of the @, still not having the domain added in the array?
this.checkEmail("[email protected]");
checkEmail(email: string) {
let emails = [
"@outlook.co",
"@otlook.es",
"@hahoo.com",
"@YAOO.COM.MX",
"@yahoo.com.mex",
"NODIOCORREO",
"NOMBRE",
"NOTENGO",
"NOVALIDO",
"PACHO"
];
for (var i = 0; i < emails.length; i++) {
if (email.indexOf(emails[i]) !== -1) console.log("encontrado");
}
The example above returns found even though it only matches the word NOTENGO and not the full email [email protected] .