Javascript startsWith endsWith Methods Example Tutorial

Reading Time: 4 minutes
998 Views

Inside this article we will see the concept i.e Javascript startsWith endsWith Methods Example Tutorial. Article contains the classified information about How to use the JavaScript startsWith() and endsWith() method.

If you are looking for a solution i.e How to Ignore case of startsWith, endsWith Methods in Javascript then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.

Learn More –

Let’s get started.

How To Use Javascript String startsWith() Method

Here,

We will use the concept of Javascript i.e JavaScript String startsWith() Method.

The startsWith() method returns true if a string starts with a specified string.

Otherwise it returns false.

The startsWith() method is case sensitive.

Example #1

//...

const str = 'Online Web Tutor';

const substr = 'Online';

console.log(str.startsWith(substr)); // true

//...

Console Output

Example #2

//...

const str = 'Online Web Tutor';

const substr = 'online';

console.log(str.startsWith(substr)); // false


//...

Console Output

Example #3

//...

const str = 'Online Web Tutor';

const substr = 'online';

console.log(str.toLowerCase().startsWith(substr.toLowerCase())); // true

//...

Console Output

How To Use Javascript String endsWith() Method

Here,

We will use the concept of Javascript i.e JavaScript String endsWith() Method.

The endsWith() method returns true if a string ends with a specified string.

Otherwise it returns false.

The endsWith() method is case sensitive.

Example #1

//...

const str = 'Online Web Tutor';

const substr = 'Tutor';

console.log(str.endsWith(substr)); // true

//...

Console Output

Example #2

//...

const str = 'Online Web Tutor';

const substr = 'tutor';

console.log(str.endsWith(substr)); // false

//...

Console Output

Example #3

//...

const str = 'Online Web Tutor';

const substr = 'tutor';

console.log(str.toLowerCase().endsWith(substr.toLowerCase())); // true

//...

Console Output

We hope this article helped you to learn Javascript startsWith endsWith Methods Example Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more