How do I split a string with multiple separators in JavaScript?
I’m trying to split on both commas and spaces, but AFAIK JavaScript’s split() function only supports one separator.
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.
Pass in a regexp as the parameter:
Edited to add:
You can get the last element by selecting the length of the array minus 1:
… and if the pattern doesn’t match: