DEV Community

Shshank
Shshank

Posted on

JavaScript startsWith() and endsWith() string methods, a brief

startsWith() and endsWith() in JavaScript are sibling methods that return a boolean true if a string starts or ends with a specific string, respectively. Else, false.

They are supported by most browsers, but Internet Explorer. They take two parameters, a search value, and a length value (optional).

Syntax: String.startsWith(string, length)

const string = "Developers love DevBytes";

string.startsWith("Dev");     // True
string.startsWith("DevBytes");   // False

string.endsWith("Bytes");     // True
string.endsWith("Dev");     // False
Enter fullscreen mode Exit fullscreen mode

Top comments (0)