Check a String Contains Another Sub-String in JavaScript

Hi readers hope you all will be fine, today in this post i show you how you can check a string contains another sub-string in JavaScript. I describe an easy to do that task.  String.indexof is a JavaScript function which find and return the position of string with in the string.

var string = “foo”,
substring = “foo”;
console.log(string.indexOf(substring) !== -1);

and when you run the code result is True.

Hope you can easily check by using above code.

About Moazzam Qureshi

I am SEO expert and web developer since 2011. My hobby is to write & provides quality content about blogging, SEO , Social Media , Earn Online and Affiliate Marketing.