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 9255161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:39:08+00:00 2026-06-18T11:39:08+00:00

I have the following code in my project: for(i = 0; i < inputArr.length;

  • 0

I have the following code in my project:

for(i = 0; i < inputArr.length; i++) {
    if(accountsBool) {
        inputArr[i] = inputArr[i].split(/\s+/);
        if (inputArr[i] == "" || !inputArr[i].match(/[^\s]/)) {
            inputArr.splice(i,1);
        }
    }
}

I’ll try to explain the issue the best I can…

I need this portion of the code to remove all whitespace and empty strings, but the lines…

inputArr[i] = inputArr[i].split(/\s+/);

and…

if (inputArr[i] == "" || !inputArr[i].match(/[^\s]/)) {
    inputArr.splice(i,1);
}

…don’t work together. I get the error, “Object doesn’t support this property or method”. If I comment out one and run the code with the other it seems to work fine. The syntax seems to be right too. Any ideas?

inputArr is an array of strings that is parsed in from a text area.

Thank you.

  • 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-18T11:39:09+00:00Added an answer on June 18, 2026 at 11:39 am

    .split() returns an array, which doesn’t work with .match().

    I need this portion of the code to remove all whitespace and empty strings, but the lines…

    You seem to be saying that items that don’t contain at least one non-whitespace character should be removed from the from the array, and any remaing items should be updated to have any whitespace removed (but keeping the other characters). If so, use .replace() first to remove the whitespace, then test whether to remove the item.

    Note that if you use .splice() in a loop you need to adjust your iterator variable i to allow for the missing element – or, simpler, loop backwards.

    for(i = inputArr.length - 1; i >= 0; i--) {
        if(accountsBool) {
            inputArr[i] = inputArr[i].replace(/\s/g,"");
            if (inputArr[i] === "") {
                inputArr.splice(i,1);
            }
        }
    }
    

    If you’re saying that items that don’t contain at least one non-whitespace character should be removed but you want to leave whitespace in place in the remaining elements then do this:

    for(i = inputArr.length - 1; i >= 0; i--) {
        if(accountsBool) {
            if (!/[^\s]/.test(inputArr[i])) {
                inputArr.splice(i,1);
            }
        }
    }
    

    Note also that if you have no other processing in your loop then you should move the if(accountsBool) test to immediately before the loop rather than doing it on every iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
I have following code that I am compiling in a .NET 4.0 project namespace
I have the following code in my ASP.NET project public sealed class IoC {
i have the following code snippet in my ANT File which compiles my project
In my Rails project I have the following code: auto_link( h( wrap_long_string(post.text,50) )).gsub(/\n/,<br />)
I have the following code. <s:push value=#session['person']> <s:if test=%{admin=='y'}> <a class=add href=/projit1/project/addProject.jsp>Create a Project</a>
For my project I have added following line of code in applicaiton.ini resources.layout.layoutPath =
I have MVC3 project & Valums file uploader . The code is following <script
I have the following code in a project that write 's the ascii representation
I have the following code: http://www.project-vanquish.co.cc/gridtest/drag-grid.html The plan is to allow the user to

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.