目录

String.prototype.startsWith(searchString, position = 0)

该方法确定字符串是否以指定字符开头。

语法 (Syntax)

str.startsWith(searchString[, position])

参数 (Parameters)

  • searchString - 要在此字符串开头搜索的字符。

  • Position - 此字符串中开始搜索searchString的位置; 默认为0。

返回值 (Return Value)

如果字符串以搜索字符串的字符开头,则为true ; 否则,是的。

例子 (Example)

var str = 'hello world!!!'; 
console.log(str.startsWith('hello'));

输出 (Output)

true 
↑回到顶部↑
WIKI教程 @2018