24.173. String.slice( ): extract a substringECMAScript v324.173.1. Synopsisstring.slice(start, end) 24.173.1.1. Arguments
24.173.1.2. ReturnsA new string that contains all the characters of string from and including start, and up to but not including end. 24.173.2. Descriptionslice( ) returns a string containing a slice, or substring, of string. It does not modify string. The String methods slice( ), substring( ), and the deprecated substr( ) all return specified portions of a string. slice( ) is more flexible than substring( ) because it allows negative argument values. slice( ) differs from substr( ) in that it specifies a substring with two character positions, while substr( ) uses one position and a length. Note also that String.slice( ) is an analog of Array.slice( ). 24.173.3. Examplevar s = "abcdefg"; s.slice(0,4) // Returns "abcd" s.slice(2,4) // Returns "cd" s.slice(4) // Returns "efg" s.slice(3,-1) // Returns "def" s.slice(3,-2) // Returns "de" s.slice(-3,-1) // Should return "ef"; returns "abcdef" in IE 4 24.173.4. BugsNegative values for start do not work in Internet Explorer 4 (but they do in later versions of IE). Instead of specifying a character position measured from the end of the string, they specify character position 0. 24.173.5. See AlsoArray.slice( ), String.substring( ) |