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