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
    
Top comments (0)