{"id":7523,"date":"2025-03-31T04:53:23","date_gmt":"2025-03-31T04:53:23","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7523"},"modified":"2025-03-31T04:53:27","modified_gmt":"2025-03-31T04:53:27","slug":"how-to-check-whether-string-contains-substring-in-javascript-2","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/","title":{"rendered":"How to Check Whether String Contains Substring in JavaScript?"},"content":{"rendered":"\n<p>Web developers may need to check if a string contains substring in JavaScript . This is required if you are providing some kind of search functionality on your site&#8217;s web pages. There are several simple ways to do this using JavaScript. In this article, we will learn how to check whether given string contains a substring or not.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#Check_Whether_String_Contains_Substring\" >Check Whether String Contains Substring<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#1_Using_includes\" >1. Using includes()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#2_Using_indexOf\" >2. Using indexOf()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#3_Using_searchregExp\" >3. Using search(regExp)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#4_Using_lastIndexOfsearchValue\" >4. Using lastIndexOf(searchValue)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#5_Using_startsWithsearchValue\" >5. Using startsWith(searchValue)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#6_Using_endsWithsearchValue\" >6. Using endsWith(searchValue)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_Whether_String_Contains_Substring\"><\/span>Check Whether String Contains Substring<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you have the following string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = 'good morning';<\/pre>\n\n\n\n<p>Here are the different ways to check if string contains substring in JavaScript.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_includes\"><\/span>1. Using includes()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can use includes() function to check if a string contains a substring or not. It returns true if the substring is present in the string, else it returns false. It is commonly used by JavaScript for this purpose. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.incudes(substring,[position])<\/pre>\n\n\n\n<p>The includes function can be called on any string variable or literal. The first argument is the substring you need to search. The second argument is optional and means the starting point where you want to start the search from.<\/p>\n\n\n\n<p>Here is an example to check if substring &#8216;good&#8217; is present in our string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.includes('good'); \/\/ returns true<\/pre>\n\n\n\n<p>Please note, includes performs a case-sensitive search so if the substring is not in the proper case, then it will return false.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.includes('Good'); \/\/ returns false<\/pre>\n\n\n\n<p>So you can convert the original string to lower\/uppercase to match the case of your substring.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.toLowerCase().includes('Good'.toLowerCase())) \/\/ returns<\/pre>\n\n\n\n<p>In the above example, the original string and substring have different cases. So we convert both of them to lowercase before calling includes function. Please note, toLowerCase() does not alter the original string but only its copy used for checking.<\/p>\n\n\n\n<p>If your original string is very large and you have a vague idea about the location of substring, then you can specify the position argument that tells includes function where to start looking. But ensure that you do not start looking after the substring&#8217;s position.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.includes('good',2); \/\/ returns false<\/pre>\n\n\n\n<p>In the above example, we have specified position as 2, whereas the substring starts from 1st letter so the result is false.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_indexOf\"><\/span>2. Using indexOf()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The indexOf() function returns the position of first occurrence of character or substring in a string. If it is not present then the function will return -1. You can call indexOf() on all string variables and literals. Here is an example to check if substring &#8216;good&#8217; is present in our substring.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.indexOf('good'); \/\/ returns 0<\/pre>\n\n\n\n<p>If you want the result to be boolean, then you can check if the result of indexOf() is &gt;=0.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.indexOf('good')&gt;=0); \/\/ returns true<\/pre>\n\n\n\n<p>Like includes() function, indexOf() is also case sensitive. So it is better to convert both original string and substring to same case before calling indexOf(), as shown in previous solution. It also accepts an optional argument that specifies the start of search. The default position is start of the string 0.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.indexOf('good',2)); \/\/ returns -1<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_searchregExp\"><\/span>3. Using search(regExp)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You can also use search function to check if a substring is present in another string. It returns index of 1st match of regular expression in the string. If no match is found, -1 is returned. You can also use literal strings, instead of regular expression. It also performs case insensitive search. Here is a basic example to check if &#8216;good&#8217; is present in &#8216;good morning&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.search('good'); \/\/ returns 0<\/pre>\n\n\n\n<p>In the above example, we have used literal string. You can also search using regular expression, enclosed within \/&#8230;\/<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.search(\/good\/); \/\/ returns 0<\/pre>\n\n\n\n<p>Here is an example to search for &#8216;GOOD&#8217; in our original string, using a case insensitive match.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a.search(\/GOOD\/i); \/\/ returns 0<\/pre>\n\n\n\n<p>Using regular expressions allows you to search for a wide range of substrings, along with options such as case insensitive search.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_lastIndexOfsearchValue\"><\/span>4. Using lastIndexOf(searchValue)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The lastIndexOf() function is the opposite of indexOf() function. It returns the position of the last occurrence of substring in a string. If the substring is not found, it returns -1. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.lastIndexOf(substring)<\/pre>\n\n\n\n<p>Here is an example to demonstrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = 'good morning, good night';<br>console.log(a.lastIndexOf('good')); \/\/ output is 14<\/pre>\n\n\n\n<p>In the above example, there are 2 occurrences of &#8216;good&#8217; in original string. lastIndexOf() function returns 14, that is, the starting position of last occurrence. <\/p>\n\n\n\n<p>You can also specify an optional parameter to specify the starting position of search.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(a.lastIndexOf('good',10)); \/\/ output is 0<\/pre>\n\n\n\n<p>In the above example, we specify the starting position as 10. Since it starts looking from the 11th character instead of the last character, it skips the 2nd occurrence of &#8216;good&#8217;. So it returns the result as 0, that is, the first occurrence.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_startsWithsearchValue\"><\/span>5. Using startsWith(searchValue)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to simply check if a substring is present at the beginning of another string, then you can also use startsWith. It returns true the given substring is found at the beginning of a string. Else it returns false. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.startsWith(substring, start)<\/pre>\n\n\n\n<p>In the above function, you need to specify the substring to be searched as the first argument. The next argument is optional. It stands for the starting position of the string at which to begin the search. It is useful if you are using a large string, or you are sure about the position of substring.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var a = 'good morning, good night';<br>console.log(a.startsWith('good')); \/\/ returns true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_endsWithsearchValue\"><\/span>6. Using endsWith(searchValue)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Similarly, JavaScript also provides endsWith() function, that allows you to check if a substring is present at the end of a string or not. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.endsWith(substring, length)<\/pre>\n\n\n\n<p>In the above function, we need to specify the substring to be searched as the first argument. Next argument is optional and means the length of the string. By default, it is equal to the length of the string. If your string is long or you know the position of substring, then you may provide a value lesser than the length of string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several different ways to check if string contains substring in JavaScript. Among them, using includes() function is the simplest way to check for a substring. If you need to search for a substring&#8217;s position in addition to checking its presence, then you can use indexOf(). We also looked several JavaScript functions built for specific use cases.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-empty-elements-from-javascript-array\/\">How to Remove Empty Elements from JavaScript Array<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-detect-invalid-date-in-javascript\/\">How to Detect Invalid Date in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-find-sum-of-array-of-numbers-in-javascript\/\">How to Find Sum of Array of Numbers in JavaScript<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.<\/p>\n","protected":false},"author":1,"featured_media":7549,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[331],"class_list":["post-7523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-substring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Check Whether String Contains Substring in JavaScript? - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Check Whether String Contains Substring in JavaScript? - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-31T04:53:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-31T04:53:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"288\" \/>\n\t<meta property=\"og:image:height\" content=\"192\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Check Whether String Contains Substring in JavaScript?\",\"datePublished\":\"2025-03-31T04:53:23+00:00\",\"dateModified\":\"2025-03-31T04:53:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/\"},\"wordCount\":994,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1\",\"keywords\":[\"substring\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/\",\"name\":\"How to Check Whether String Contains Substring in JavaScript? - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1\",\"datePublished\":\"2025-03-31T04:53:23+00:00\",\"dateModified\":\"2025-03-31T04:53:27+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/03\\\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1\",\"width\":288,\"height\":192,\"caption\":\"search substring in javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Check Whether String Contains Substring in JavaScript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Check Whether String Contains Substring in JavaScript? - Ubiq BI","description":"Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/","og_locale":"en_US","og_type":"article","og_title":"How to Check Whether String Contains Substring in JavaScript? - Ubiq BI","og_description":"Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-03-31T04:53:23+00:00","article_modified_time":"2025-03-31T04:53:27+00:00","og_image":[{"width":288,"height":192,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Check Whether String Contains Substring in JavaScript?","datePublished":"2025-03-31T04:53:23+00:00","dateModified":"2025-03-31T04:53:27+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/"},"wordCount":994,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1","keywords":["substring"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/","name":"How to Check Whether String Contains Substring in JavaScript? - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1","datePublished":"2025-03-31T04:53:23+00:00","dateModified":"2025-03-31T04:53:27+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often you may need to check if string contains substring in JavaScript. Here are the different ways to do it.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1","width":288,"height":192,"caption":"search substring in javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Check Whether String Contains Substring in JavaScript?"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/03\/search-substring-in-javascript.jpg?fit=288%2C192&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Xl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7523"}],"version-history":[{"count":25,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7523\/revisions"}],"predecessor-version":[{"id":7550,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7523\/revisions\/7550"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7549"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}