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.
So what I am doing is taking a string and splitting it at all
Share
Use the
lengthof the array that holds the separated strings:For example, with the following code:
JS Fiddle demo.