Check for Partial Match in an Array

后端 未结 5 1254
长情又很酷
长情又很酷 2021-01-26 03:23

I have a JavaScript array that contains some words that cannot be used when requesting user accounts to be created.

I am trying to loop over the accounts requested and c

5条回答
  •  野的像风
    2021-01-26 03:52

    I fixed some of the things...

    for (var x = 0; x < newAccounts.length; x++) // loop through new accounts
    {
        // for every account check if there is any match in blacklist array
        for (var y = 0; y < blacklist.length; y++) 
        {
          // if there is match do something 
          if (newAccounts[x].indexOf(blacklist[y]) > -1)
          {
              alert(newAccounts[x] + " is in the blacklist array");
              break;
          }
      }
    
    }
    

提交回复
热议问题