slice()
works as substring()
with some different behaviors.
Syntax
string.Slice(start, stop);
string.substring(start, stop);
What they have in common:
If start equals stop: returns an empty string
If stop is omitted: extracts characters to the end of the string
If one of the arguments is longer than the string length, the string length will be used instead.
Distinctions of substring():
If start > stop, then substring will swap these 2 arguments.
If one of the arguments is negative or is Nan, it will be treated as 0.
Distinctions of Slice():
If start > stop, Slice() will NOT swap the 2 arguments.
If start is negative: sets char at the end of the string, exactly as substr() in Firefox. This behavior is observed in Firefox and IE.
If stop is negative: sets stop to: string.length - Math.abs(stop) (original value), except limited to 0 (hence Math.max (0, string.length + stop)) as covered in the ECMA specification .
Source
And then grandpa, no answer was good?
– Sam