One option is to use regular expressions:
if (str.match("^Hello")) {
// do this if begins with Hello
}
if (str.match("World$")) {
// do this if ends in world
}
Answer from Lukáš Lalinský on Stack OverflowW3Schools
w3schools.com › jsref › jsref_startswith.asp
JavaScript String startsWith() Method
The startsWith() method returns true if a string starts with a specified string.
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › startsWith
String.prototype.startsWith() - JavaScript - MDN Web Docs
const str = "To be, or not to be, that is the question."; console.log(str.startsWith("To be")); // true console.log(str.startsWith("not to be")); // false console.log(str.startsWith("not to be", 10)); // true
jQuery
api.jquery.com › attribute-starts-with-selector
Attribute Starts With Selector [name^=”value”] | jQuery API Documentation
Description: Selects elements that have the specified attribute with a value beginning exactly with a given string · attribute: An attribute name
Top answer 1 of 6
407
One option is to use regular expressions:
if (str.match("^Hello")) {
// do this if begins with Hello
}
if (str.match("World$")) {
// do this if ends in world
}
2 of 6
104
For startswith, you can use indexOf:
if(str.indexOf('Hello') == 0) {
...
ref
and you can do the maths based on string length to determine 'endswith'.
if(str.lastIndexOf('Hello') == str.length - 'Hello'.length) {
Can I Use
caniuse.com › mdn-javascript_builtins_string_startswith
JavaScript built-in: String: startsWith | Can I use... Support tables for HTML5, CSS3, etc
"Can I use" provides up-to-date browser support tables for support of front-end web technologies on desktop and mobile web browsers.
Scaler
scaler.com › home › topics › javascript string startswith()
JavaScript String startsWith() Method - Scaler Topics
March 4, 2024 - The startsWith() method in JavaScript is designed to determine if a string begins with specified characters.
GeeksforGeeks
geeksforgeeks.org › jquery › how-to-check-a-string-starts-ends-with-a-specific-string-in-jquery
How to check a string starts/ends with a specific string in jQuery ? - GeeksforGeeks
July 12, 2025 - </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body> <h1 id="text"> Welcome To GEEKS FOR GEEKS!!! </h1> <h2> Check whether a word is present in the above sentence </h2> <input type="text" id="startkey"> <input type="text" id="endkey"> <button onclick="MyFunction()"> Check </button> <h2> startsWith() and endsWith() method </h2> <h2 id="startswith"> </h2> <h2> indexOf() method </h2> <h2 id="indexOf"></h2> <h2> search() method </h2> <h2 id="search"></h2> <h2> substring() method </h2> <h2 id="substring"></h2> <h2> substr() method </h2>
TutorialsPoint
tutorialspoint.com › article › how-to-check-a-string-starts-ends-with-a-specific-string-in-jquery
How to Check a String Starts/Ends with a Specific String in jQuery?
July 19, 2023 - <!DOCTYPE html> <html> <head> <title>String Start/End Check</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <div> <h2>String: "Hello, World!"</h2> <button id="checkStart">Check if starts with "Hello"</button> <button id="checkEnd">Check if ends with "World!"</button> <div id="result"></div> </div> <script> $(document).ready(function() { let text = "Hello, World!"; $('#checkStart').click(function() { let result = text.startsWith('Hello'); $('#result').html('Starts with "Hello": ' + result); }); $('#checkEnd').click(function() { let result = text.endsWith('World!'); $('#result').html('Ends with "World!": ' + result); }); }); </script> </body> </html>
JavaScript Tutorial
javascripttutorial.net › home › javascript string methods › string.prototype.startswith()
JavaScript String startsWith() Method
November 3, 2024 - You will learn how to use the JavaScript String startsWith() method to check if a string begins with the characters of another string.
Jquery
forum.jquery.com › portal › en › community › topic › jquery-startswith-endswith
[jQuery] startsWith / endsWith
Unable to process your request · Sorry! Your request cannot be processed right now. Please try again later · Go to home page
Code.mu
code.mu › en › javascript › manual › string › startsWith
The startsWith method - checking the start of a string in JavaScript
The startsWith method checks if a string starts with the substring specified in the first parameter. If it starts, then it returns true, and if it doesn't, then false.
TechOnTheNet
techonthenet.com › js › string_startswith.php
JavaScript: String startsWith() method
This JavaScript tutorial explains how to use the string method called startsWith() with syntax and examples. In JavaScript, startsWith() is a string method that is used to determine whether a string starts with a specific sequence of characters.
Telerik
telerik.com › javascript › ui › filter › operators.string.startswith
operators.string.startswith - API Reference - Kendo UI Filter - Kendo UI for jQuery
<div id="filter"></div> <script> var data = [ { name: "Jane Doe", age: 30 }, { name: "John Doe", age: 33 } ]; var dataSource = new kendo.data.DataSource({ data: data }); $("#filter").kendoFilter({ dataSource: dataSource, operators: { string: { startswith: "Begins with" } }, fields: [ { name: "name", type: "string", label: "Name" } ] }); </script>
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_startswith.asp.html
JavaScript String startsWith() Method
Note: The startsWith() method is case sensitive. ... Color Converter Google Maps Animated Buttons Modal Boxes Modal Images Tooltips Loaders JS Animations Progress Bars Dropdowns Slideshow Side Navigation HTML Includes Color Palettes Code Coloring ... Your message has been sent to W3Schools. HTML Tutorial CSS Tutorial JavaScript Tutorial W3.CSS Tutorial Bootstrap Tutorial SQL Tutorial PHP Tutorial jQuery ...
Codecademy
codecademy.com › docs › javascript › strings › .startswith()
JavaScript | Strings | .startsWith() | Codecademy
August 8, 2023 - The .startsWith() JavaScript string method checks whether a string begins with the specified characters.
Daily Dev Tips
daily-dev-tips.com › posts › javascript-startswith-and-multiple-conditions
JavaScript startsWith and multiple conditions
December 1, 2021 - const string = 'Hi, and welcome from JavaScript'; console.log(string.startsWith('Hi')); // true console.log(string.startsWith('Hello')); // false