How to know that a string starts/ends with a specific string in jQuery?

I want to know if a string starts with the specified character/string or ends with it in jQuery.

For Example:

var str="Hello World";

if( str starts with 'Hello' ) {
   alert('true');
} else {
   alert('false');
}

if( str ends with 'World' ) {
   alert('true');
} else {
   alert('false');
}

If there is not any function then any alternative ?

6 Answers
6

Leave a Comment