How to check if a string has a certain piece of text in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The jQuery search() method is used to check whether a string contains a certain text in JavaScript.

You can try to run the following code to check whether “Tutorialspoint: Free Video Tutorials” contains the “Free Video” text in JavaScript or not:

      <title>JavaScript String search() Method</title>
         var re = "Free Video";
         var str = "Tutorialspoint: Free Video Tutorials";
         if ( == -1 ) {
            document.write("Does not contain" );
         } else {
            document.write("Contains" );
Published on 02-Jan-2018 13:06:55