How would I get word # n in a string with javascript. I.e. if I want to get word #3 in “Pumpkin pie and ice cream”, I want “and” returned. Is there some little function to do this, or could someone write one? Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Use the
string.split()method to split the string on the ” ” character and then return the nth-1 element of the array (this example doesn’t include any bounds checking so be careful):