Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9214391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:57:54+00:00 2026-06-18T01:57:54+00:00

In summary I am trying to build a swear filter where I have a

  • 0

In summary I am trying to build a swear filter where I have a static array called “badWords” which holds many profane words.

My script then lifts all text values from a form into another array called “fieldValues”.

It then iterates through the fieldValues and should compare the string values with the whole array of “badWords” and if found trigger a simple response for now.

The code is not producing any errors but it is not producing expected outputs either, I was hoping you could give me insight into where I went wrong with it.

Code

// get all the inputs from "editor_form"
var $inputs = $('#editor_form :input');

var fieldValues = new Array();
var i = 0;

//for each field place it in array
$inputs.each(function() 
{
    fieldValues[i] = $(this).val();
    i++;
});

var swearWord;
for (i = 0; i < fieldValues.length; i++)
{
    if (fieldValues[i] == function()
    {
        //this bit i think is wrong, i think it only does one loop in this level then jumps back up
        for (x = 0; x < badWords.length; x++)
        {
            return badWords[x];
        }
    })

    //warning message   
    {
        window.alert("Bad word found");
    }       
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:57:55+00:00Added an answer on June 18, 2026 at 1:57 am

    First, you can fix your existing code like this :

    function isBad(word) {
         for (x = 0; x < badWords.length; x++) {
             if (badWords[x]==word) return true;
         }
         return false;
    }
    for (i = 0; i < fieldValues.length; i++) {
       if (isBad(fieldValues[i])) {
           window.alert("Bad word found : " + fieldValues[i]);
       }
    }
    

    But your bad words form, logically, a set, not an array. You should use an object as map to find them in a fast way.

    // build a set of the bad words
    var badWordsSet = {};
    for (x = 0; x < badWords.length; x++) badWordsSet[badWords[x]]=true;
    // then use it
    for (i = 0; i < fieldValues.length; i++) {
       if (badWordsSet[fieldValues[i]]) {
           window.alert("Bad word found : " + fieldValues[i]);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write documentation comments however I have a problem. /// <summary>
I am trying to do a summary for my android daily rom build. and
So I'm trying to build a async server... Here is a summary of what
I have to build a small OpenGL wrapper for a work. I'm trying to
I'm trying to build a custom gem I wrote called client_package but it is
Summary I currently have a NAnt build script that performs a vssget on either
I have some Java projects with me and I am trying to build it
Summary: I'm trying to write a text string to a column of type varchar(max)
Summary: I'm trying to do classification of some images depending on the angles between
im trying to make a small name summary function depending on the size of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.