I have a string like this.
var a="1:2:3:";
I want to split it with a.split(":") to remove the “:” colon character.
I want to get this as the result:
["1","2","3"]
But instead the result of a.split(":") is this:
["1","2","3",""]
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 this trim method to remove the trailing colon.
Then you can call it like this:
If you wanted to you could of course make
TrimColona string prototype method, allowing you to do something like this:In case you’d like an explanation of the regex used: Go here