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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:05:01+00:00 2026-05-30T13:05:01+00:00

So what I am doing is taking a string and splitting it at all

  • 0

So what I am doing is taking a string and splitting it at all the spaces. I already did this using .split(" ")[0/1/2] but how do I then take those individual strings and determine the length? The reason I am doing this is to check that string if it has a middle initial or not. Given a name like this John M Smith, I can determine what the words are but if somebody does not enter a middle initial, the last name will now be placed in the middle initial variable. How would I go about doing this or am I tackling it all wrong? Thanks for the help.

  • 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-30T13:05:02+00:00Added an answer on May 30, 2026 at 1:05 pm

    Use the length of the array that holds the separated strings:

    var separateStrings = stringVar.split(' ');
    var numOfNames = separateStrings.length;
    

    For example, with the following code:

    var i = document.getElementById('names'); // assuming an input element of id="names"
    
    i.onkeydown = function(e){
        if (e.keyCode == 13){
            var stringVar = this.value,
                separatedNames = stringVar.split(' '),
                numOfNames = separatedNames.length;
    
            alert(numOfNames);
        }
    
    };​
    

    JS Fiddle demo.

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

Sidebar

Related Questions

I'm taking a look at TDD using GoogleTest and I was doing this kata:
After taking a look at this SO question and doing my own research, it
I am trying to draw a string using quartz 2d. What i am doing
To explain what I'm doing, I'm basically taking a string of X's and O's
I am doing an application where I am using the following link http://iosdevelopertips.com/cocoa/date-formatters-examples-take-3.html to
We have a rather large SVN repository. Doing SVN updates are taking longer and
I am talking about doing something like this: LOCK TABLE page WRITE; SELECT *
Doing an ajax get request works as expected using the following code: $.ajax({ type:
How can I get the first character in a string using Ruby? Ultimately what
Hi I have a web service that is doing huge computation and is taking

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.