[Javascript] How can I check if a string is ends with another string?
I want to check if a string is ended with a particular string, for example, I want to check if a string ends with *. How can I do that in Javascript?
2 Answers
4 years ago by Jahaan
I tried using endswith() method which worked for me.
4 years ago by Jahaan
Use either endsWith() or extract the substring at the end and match with the substring as shown below
let str = "Hello world*";
let endString ='*'
console.log(str.endsWith(endString));
console.log(str.substr(str.length - endString.length) === endString);
4 years ago by Meera