Languages
[Edit]
EN

JavaScript - string contains case insensitive

0 points
Created by:
elmer
646

In this article, we would like to show you how to check if a string contains a word (case insensitive) in JavaScript.

1. Check if the string contains the word

Edit

In this example, we convert whole text string to lowercase, then we search for the word (also in lowercase) to find out if the word is present in the string (true) or not (false).

 

2. Find the index of the word

Edit

This example is similar to the first one, but in this one we use indexOf() method to find the index of the word that we search for.

References

Edit
  1. String.prototype.indexOf() - JavaScript | MDN

Alternative titles

  1. JavaScript - string contains ignore case
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join