记录一下js的startsWith方法

startsWith方法,用来判断字符串是否以固定数据开头。

'abc'.startsWith('a')	//true
'abc'.startsWith('d')	//false

该方法还有第二个参数,可以从字符串指定位置开始判断,默认为0

'abcdefg'.startsWith('bcd'))	//false
'abcdefg'.startsWith('bcd',1))	//true

同理还有endsWith方法,第二个参数为所选字符串指定长度

'abc'.endsWith('c') 	//true
'abc'.endsWith('bc') 	//true
'abc'.endsWith('a') 	//false
'abcdefg'.endsWith('def'))  //false
'abcdefg'.endsWith('def',6))    //true

猜你喜欢

转载自blog.csdn.net/qq_30627241/article/details/131212513