The String startsWith() method is used to check a string content and see if it starts with a specific value or not.
String startsWith() Method Parameters:
The startsWith() method takes two arguments:
- The first argument is the string value that we want to search for in the target text content and see if that text starts with this string value.
- The second argument is the position from which we want this search to start from. This second argument is optional and, if ignored, then the search begins from the index 0 for the text content (which is the first character).
String startsWith() Method Return Value:
The return value of this method is either true or false.
If the value is true, that means the target text content starts with the value we set as the first argument of this method.
If the value is false, that means the target text content starts with another string value (other than the one we’ve set as the argument of the method).
const id = "If you work hard, then dreams will come true"; const res = id.startsWith("If you work hard"); console.log(res);