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

shshank

Shshank

Posted on July 25, 2022

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
πŸ’– πŸ’ͺ πŸ™… 🚩
shshank
Shshank

Posted on July 25, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related