substr() is similar to slice().
The difference is that the second parameter specifies the length of the extracted part.
var str = "Apple, Banana, Kiwi";
var res = str.substr(7,6);
If the first parameter is negative, the position counts from the end of the
string.var res = str.substr(7,6);
The second parameter can not be negative, because it defines the length.
If you omit the second parameter, substr() will slice out the rest of the string.
No comments:
Post a Comment