I know about .split( “-” ,2), but how can i make something like this
var str = "123-341235";
alert( str.split( "-",2 ) . [2] )<--- to get second one (341235) value?
Tnx for help All!
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.
I see two simple solutions, which have roughly the same performance:
This jsPerf benchmark shows the “slice/indexOf” solution to be about twice as fast on Chrome and Firefox.
Note that for either solution you’ll have to check that the hypen character really exists before retrieving the second part of the string; I would bet that adding the check still leaves the “slice/indexOf” solution to be much faster.