var arr = []; //new storage
str = str.split(' '); //split by spaces
arr.push(str.shift()); //add the number
arr.push(str.join(' ')); //and the rest of the string
//arr is now:
["72","tocirah sneab"];
var arr1 = split_on_first_word("72 tocirah sneab"); // Result: ["72", "tocirah sneab"]
var arr2 = split_on_first_word(" 72 tocirah sneab "); // Result: ["72", "tocirah sneab"]
var arr3 = split_on_first_word("72"); // Result: ["72", ""]
var arr4 = split_on_first_word(""); // Result: ["", ""]
function split_on_first_word(str)
{
str = str.trim(); // Clean string by removing beginning and ending spaces.
var arr = [];
var pos = str.indexOf(' '); // Find position of first space
if ( pos === -1 ) {
// No space found
arr.push(str); // First word (or empty)
arr.push(''); // Empty (no next words)
} else {
// Split on first space
arr.push(str.substr(0,pos)); // First word
arr.push(str.substr(pos+1).trim()); // Next words
}
return arr;
}