String.startsWith method
String › startsWith
Official
Checks if the string starts with a specific substring.Signature:
startsWith(searchString: string, position?: number | undefined): booleanParameters:
| Parameter | Type | Description |
|---|---|---|
| searchString | string | The substring to check for. |
| position? | number | undefined | The position to start checking from. |
Returns: boolean — true if the string starts with the substring, false otherwise.
Example:
console.log('foo'.startsWith('fo')); // trueconsole.log('foo'.startsWith('oo')); // falseconsole.log('foo'.startsWith('foo', 1)); // falseconsole.log('foo'.startsWith('oo', 1)); // true