JavaScript startsWith() and endsWith() string methods, a brief
Shshank
Posted on July 25, 2022
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
π πͺ π
π©
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
javascript Leveraging JavaScript's Set and Map for an Efficient Content Management System
September 2, 2024
javascript How to add a Who-Is-Online feature on your application with JavaScript
September 19, 2024
javascript Understanding the Fetch API: The Future of Network Requests in Web Development
August 20, 2024