Includes Method in JavaScript With Example

In this tutorial we will learn about includes() function in JavaScript.

include function in javascript
include function in javascript

How to Use includes() Function in JavaScript?

Generally it compares two string and returns true if string contains the specific string otherwise it returns false. It also returns true if some of part completely matches the string.

=> includes(value, position)


let str = "my name is rakesh saini"
let result = str.includes("rak");

Answer:
true

We can also provide the starting position from there start searching in the includes() function in the second position. See the example below: It will search from the 44th position. rakesh comes before the 44th position so it will return false.

Note: This includes() method in JavaScript is case sensitive. Means value provides inside the function is case sensitive. You can convert both string into toLowerCase() if the value is taken using a variable or dynamic.


let str = "my name is rakesh saini"
let result = str.includes("rak", 44);

Answer:
false

Thanks you for visiting the page on FlutterTpoint. See Sorting in JavaScript.

Please visit more Useful Tutorials.

close

Don’t miss new tips!

We don’t spam! Read our [link]privacy policy[/link] for more info.

Leave a Comment