var string = abc123;
string.split(*POSITION=3)???
Is there a way to split this string into an array of strings that is [abc,123]?
Is the split method the right thing to use?
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 would say the
splitmethod is not the right thing to use here, as its purpose is to segment a string based on a certain character.You could certainly write your own function, of course:
If you wanted to write
"123abc".partition(3)instead, you could make that possible by extendingString.prototype:Personally, though, I’d recommend avoiding that sort of tomfoolery (search the web for “extending built-in objects in JavaScript” if you want to read what others have to say on the topic).