Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  143] [ 5]  / answers: 1 / hits: 93145  / 11 Years ago, mon, december 9, 2013, 12:00:00

I know there are several ways to split an array in jQuery but I have a special case:
If I have for example this two strings:



 G09.4 What
A04.3 A new Code


When I split the first by ' ' I can simply choose the code in front with [0] what would be G09.4. And when I call [1] I get the text: What



But when I do the same with the second string I get for [1] A but I want to retrieve A new Code.



So how can I retrieve for each string the code and the separate text?


More From » javascript

 Answers
20

Use



var someString = A04.3  A new Code;
var index = someString.indexOf( ); // Gets the first index where a space occours
var id = someString.substr(0, index); // Gets the first part
var text = someString.substr(index + 1); // Gets the text part

[#73837] Saturday, December 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxd

Total Points: 568
Total Questions: 100
Total Answers: 101

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;