How to check whether a string contains a substring in JavaScript without jQuery

You can use the following code to check whether a string contains a substring in JavaScript without jQuery.

 var string = "main string",
 substring = "ain";
 string.indexOf(substring) !== -1;

Published: January 08 2018

blog comments powered by Disqus