ES6 - New String Method startsWith


Advertisements

The method determines if a string starts with the specified character.

Syntax

str.startsWith(searchString[, position])

Parameters

  • searchString − The characters to be searched for at the start of this string.

  • Position − The position in this string at which to begin searching for searchString; defaults to 0.

Return Value

true if the string begins with the characters of the search string; otherwise, false.

Example

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

Output

true 
es6_new_string_methods.htm
Advertisements