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

  • Home
  • SEARCH
  • 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 3346080
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:15:41+00:00 2026-05-18T01:15:41+00:00

I have a script that I am working on that I am a little

  • 0

I have a script that I am working on that I am a little lost on.

I grab a user input (using jQuery) and then loop through an array and see if a phrase from the array exists in the user input. If it is found I am popping up an alert box telling them its found. But for some reason its not working.

Code:

submit = false;

            for(i in keyphrases_array) {
                if(english_text.indexOf(keyphrases_array[i]) != -1) {
                    if(trans_text.indexOf(keyphrases_array[i]) != -1) {
                        submit = false;
                    }
                } else {
                    submit = true;
                }
            }

keyphrases_array is a global array that is set in another function.

Example:

If in my array I have the phrase “Hello World” and my script finds Hello World in the english_text variable it then checks the user submitted text (trans_text). If the phrase is not found in trans_text then the script should return false.

  • 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-05-18T01:15:42+00:00Added an answer on May 18, 2026 at 1:15 am

    First, you shouldn’t use for/in to iterate over an array. Use a plain for loop.

    The problem is likely that the value of submit is being overwritten by the next iteration in the loop. If that’s the end of the function, you should return immediately.

    submit = false;
    
    for(var i = 0; i < keyphrases_array.length; i++) {
        if(english_text.indexOf(keyphrases_array[i]) != -1) {
              if(trans_text.indexOf(keyphrases_array[i]) != -1) {
                      // return immediately
                    return false;
              }
         } else {
               submit = true;
         }
    }
    return submit;
    

    or if there needs to be more processing, you can just break the loop:

    submit = false;
    
    for(var i = 0; i < keyphrases_array.length; i++) {
        if(english_text.indexOf(keyphrases_array[i]) != -1) {
              if(trans_text.indexOf(keyphrases_array[i]) != -1) {
                   submit = false;
                   break;
              }
         } else {
               submit = true;
         }
    }
    

    EDIT: Based on your comment, it seems that you want to return false if the text is not found in trans_text. This would meant that the test should use == instead of !=.

          if(trans_text.indexOf(keyphrases_array[i]) == -1) {
                  // return immediately
                return false;
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I'm working on a little script that will make something easier for me.
Ok, so I have this PHP script that runs in a nice little infinite
Ok, I have this script working 99% of how it should be working, but
I wrote a bash script that fetches lyrics from a website. The script is
I am writing a bash script that needs to print the date of the
I'm working on a CMS at the moment and have been looking for a
I have a shell script I use for deployments. Since I want to capture
I would like to write a script main.r that returns the workspace to the
Alright so i found a code and it seems to be working but I
First of all, thanks so much to everyone who has helped me on this

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.