ES6 - String.prototype.startsWith()



It determines whether a string begins with the characters of a specified string. This function returns true or false.

Syntax

The syntax given below is for String.prototype.startsWith(), where, searchString is the characters to be searched for at the start of this string. position is an optional parameter. It represents the position in this string at which to begin searching for searchString. The default value is 0.

str.startsWith(searchString[, position])

Example

let company='TutorialsPoint'
console.log(company.startsWith('Tutorial'))
console.log(company.startsWith('orial',3)) // 3 is index

The output of the above code will be as shown below −

true
true
Advertisements