You can use the startsWith() method.This method returns true if the string starts with the specified substring; otherwise, it returns false.
Syntax:
string.startsWith(searchString, position)
Example:
const str = 'Hello, world!';
console.log(str.startsWith('Hello')); // Output: true
console.log(str.startsWith('world')); // Output: false
console.log(str.startsWith('world', 7)); // Output: true