.startsWith()
Anonymous contributors
Anonymous contributors
Anonymous contributors
Published Jun 20, 2021Updated Sep 3, 2021
Contribute to Docs
The .startsWith()
Python string method checks whether a string begins with the specified characters. It will only return a boolean value, either true
or false
.
Syntax
string.startsWith(substring, position);
- The
substring
is the specified characters. - The
position
is optional. It is used to start searching forsubstring
. It starts at 0.
Example 1
Checking if a string starts with specified characters:
console.log('Do you prefer coffee or tea?'.startsWith('Do'));// Output: true
Example 2
Checking if a string starts with specified characters with a specified position:
console.log('Do you prefer coffee or tea?'.startsWith('coffee', 14));// Output: true
All contributors
- Anonymous contributorsAnonymous contributors
- Anonymous contributors
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.