Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Created May 21, 2015 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjamincharity/5fe1bb5769bcc9fac002 to your computer and use it in GitHub Desktop.
Save benjamincharity/5fe1bb5769bcc9fac002 to your computer and use it in GitHub Desktop.
Split a string at the first space.
var myString = 'foo bar baz';
var firstWord = myString.substr( 0, myString.indexOf(' ') ); // 'foo'
var stringRemainder = myString.substr( myString.indexOf(' ') + 1 ); // 'bar baz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment