How to check if a string contains a substring in ES6?

September 28, 2022 No comments javascript js string substring contains es

Introduction

In JavaScript, we may wish to check if a string contains a substring in ES6.

In this short tutorial, we'll learn how to check if a string contains another substring.

How to check if a string contains a substring in ES6

To check if a string contains a substring in ES6 we use string.includes(...) method.

const string = "foo";
const substring = "oo";

console.log(string.includes(substring)); // true

The string.includes(substring) method returns true if string contains a substring otherwise false.

Conclusion

To find out if a string contains another substring in ES6 we use string.includes(...) method.

{{ message }}

{{ 'Comments are closed.' | trans }}