开发学院

您的位置:首页>教程>正文

教程正文

ES6 新的String对象方法startsWith

ES6 新的String对象方法startsWith

   该方法确认字符串是否searchString开头,如果以searchString开头,则返回true,否则返回false;position用于指定要检查的字符串的开始位置。

语法

str.startsWith(searchString[, position])

参数

searchString − 要检查的字符串.

Position − 指定要检查的字符串的开始位置

返回值

  如果以searchString开头,则返回true,否则返回false;position用于指定要检查的字符串的开始位置。

例子

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

输出

true