We're live-coding on Twitch! Join us! FREE Webinar: Should I use React or Vue?


The startsWith method takes a string parameter and checks if the calling string starts with the value provided. It returns a Boolean value, true if the string starts with the provided value and false if not. It is case sensitive meaning the case of the search term needs to match that of the calling string.

"The lazy brown fox just couldn't move".startsWith("The")
// true

This method:

  • Takes a string value.
  • Checks if the calling string object begins with the provided parameter.
  • Returns true or false


const search = string.startsWith(searchTerm, startIndex)

2 Parameters

searchTerm The term to be searched for at the start of the string.

startIndex The start index to begin searching for the searchTerm. It defaults to 0

Returns a boolean

It returns true if the string starts with the searchTerm and false if otherwise.

Common Uses and Snippets

Checking if a initial contents of a string matches a specific string.

Like this article? Follow @iChuloo on Twitter