How to Check if a String Starts with a Character in JavaScript
In this lesson, we will see how to check if a string starts with a desired character in JavaScript, sometimes we want to check if a given string starts with a specified character so how we can do that?
The startsWith() method
To do that we can use the startsWith() method that returns true if a string starts with a given character if not it returns false.
const sayHello = 'Hello World';
console.log(sayHello.startsWith('H'));
// true