js string interception method

1,slice(a, b)

The first parameter indicates the starting position, the second one is taken to but not including

About the parameters of positive and negative issues, just remember one thing: never backwards interception! Otherwise, it returns an empty string

 

2,substring(a, b)

The first parameter indicates the starting position, the second one is taken to but not including

About the parameters of positive and negative issues, just remember one thing: any argument is negative, it will be converted to 0, then the smaller one on the first argument as a starting position.

 

3,substr(a, b)

The first parameter indicates the starting position, the second one is taken to be the length of

About the parameters of positive and negative issues, just remember one thing: The second parameter is negative, it goes to 0, and then returns an empty string

 https://www.cnblogs.com/yanchenyu/p/8026336.html

Guess you like

Origin www.cnblogs.com/sunny3158/p/11598823.html