Javascript startsWith endsWith Methods Example Tutorial

Share this Article
Reading Time: 4 minutes
338 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.

Buy Me a Coffee

Online Web Tutor invites you to try Skillshare free for 1 month! Learn CakePHP 4, Laravel APIs Development, CodeIgniter 4, Node Js, etc into a depth level. Master the Coding Skills to Become an Expert in Web Development. So, Search your favourite course and enroll now. Click here to join.

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.

Was this post helpful?

Learn Web Development Courses Risk Free @ $5 only.
Web Development Courses @ $5