• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / JavaScript / JavaScript String endsWith Method

JavaScript String endsWith Method

August 29, 2022 Leave a Comment

Using the JavaScript String endsWith() method, we can check to see if a string ends with a certain character or string. The endsWith method is used on a string and takes a string as its parameter.

someString.endsWith("anotherString");

Let’s take a look at an example of this below.


Let’s say we have the following JavaScript:

var someString = "This is some example text";

If we want to see if the string someString ends with the string “text”, then we can use the endsWith() method to let us know.

var someString = "This is some example text";

console.log(someString.endsWith("text"));

#Output
true

The endsWith method is case-sensitive, so note that if we tried entering “Text” in with an uppercase “T”, we would get a different result.

var someString = "This is some example text";

console.log(someString.endsWith("Text"));

#Output
false

Check if a String Starts with a Certain Character or String

To check if a String starts with a different string, we can use the startsWith() method. This works the same way as the endsWith() method but just checks the start of the string, not the end.

someString.startsWith("anotherString");

Similarly as we did above, if we want to check if the string someString starts with the string “This”, then we can use the startsWith() method to let us know.

var someString = "This is some example text";

console.log(someString.startsWith("This"));

#Output
true

The startsWith method is also case-sensitive.

Hopefully this article has been useful for you to learn how to use the JavaScript String endsWith method.

Other Articles You'll Also Like:

  • 1.  Using JavaScript to Declare Multiple Variables
  • 2.  Using JavaScript to Remove Duplicates From Array
  • 3.  Using JavaScript to Create a Unique Array
  • 4.  Creating a JavaScript Function to Subtract Two Numbers
  • 5.  Using JavaScript to Format the Date in mm dd yyyy
  • 6.  How to Clear a Textarea Field In JavaScript
  • 7.  How to Convert Degrees to Radians Using JavaScript
  • 8.  Using JavaScript to Get the Host URL
  • 9.  React Axios Interceptor to Prevent Infinite Loops in JWT Authentication
  • 10.  Add Years to a Date Using JavaScript

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy