Created
June 28, 2012 08:17
-
-
Save raspo/3009858 to your computer and use it in GitHub Desktop.
Split string only once
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function splitOnce( str, sep ){ | |
var components = str.split( sep ), | |
result = []; | |
result[0] = components.shift(); | |
result[1] = components.join( sep ); | |
return result; | |
} | |
// Example | |
var string = 'key=value&key2=value2&key3=value3'; | |
splitOnce( string, '=' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment