Split string into two parts

javascript

Solution

Use

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

Problem

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?

Original source

Related problems