Navigate back to the homepage

How to check if a string contains a specific character in JavaScript?

Infinitbility
JavaScript
May 29th, 2022 · 1 min read

Hi Friends 👋,

Welcome To Infinitbility! ❤️

Today, I’m going to show How do I check if a string contains a specific character in Javascript, here I will use the javascript string includes() method to check if a string contains a specific character or not.

What is a includes() method?

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

Let’s start the today’s tutorial How do you check if a string contains a specific character in JavaScript?

Let’s understand how we can do it

  1. Create a string variable
  2. Use the includes() method and pass specific character
  3. Console the which string contains a specific character
1// Create a string variable
2const str = 'Hello world';
3const char = 'e';
4
5// Use `includes()` method and pass specific character
6// Console the which string contains a specific character
7console.log(str.includes(char)); // 👉️ true
8
9if (str.includes(char)) {
10 // 👉️ string contains the character
11}

The above program is the simplest way to check string contains a specific character or not. let’s check the output.

javascript, check if a string contains a specific character example
javascript, check if a string contains a specific character example

I hope it’s help you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

How to check special characters in string in javascript?

Example of check special characters in string in javascript with step by step guide.

May 29th, 2022 · 1 min read

How to check if a string is a pangram in JavaScript?

Example of check if a string is a pangram in javascript with step by step guide.

May 28th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]