Wednesday, 1 April 2015

What is mean by substr() in Javascript ? what is the use ?


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.
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