startsWith()
ES6+Determines whether a string begins with the characters of a specified string.
Syntax
string.startsWith(searchString, position)Parameters
searchString string The characters to search for at the start
position number optionalPosition to begin searching
Return Value
boolean
true if the string starts with the given characters
Examples
JavaScript
const str = 'Hello World';
console.log(str.startsWith('Hello'));
console.log(str.startsWith('World')); Output:
// true
false