{"id":5391,"date":"2024-11-05T07:36:22","date_gmt":"2024-11-05T07:36:22","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=5391"},"modified":"2024-11-05T07:43:37","modified_gmt":"2024-11-05T07:43:37","slug":"how-to-check-whether-string-contains-substring-in-javascript","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/","title":{"rendered":"How to Check Whether String Contains Substring in JavaScript"},"content":{"rendered":"\n<p>JavaScript developers heavily depend on strings to perform all kinds of operations. Every website and web application uses string manipulations. While working with strings, often web developers need to check if a string contains substring in JavaScript. There are several ways to do this in JavaScript. In this article, we will learn how to check whether string contains substring in JavaScript.<\/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\/#How_to_Check_Whether_String_Contains_Substring_in_JavaScript\" >How to Check Whether String Contains Substring in JavaScript<\/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\/#1_Using_includes_function\" >1. Using includes() function<\/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_Using_indexOf_function\" >2. Using indexOf() function<\/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\/#3_Using_test_function\" >3. Using test() function<\/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\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Check_Whether_String_Contains_Substring_in_JavaScript\"><\/span>How to Check Whether String Contains Substring in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to check whether string contains substring in JavaScript.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_includes_function\"><\/span>1. Using includes() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The includes() function checks if a string contains a substring and returns True if the string is present. Else it returns False. It is available in every string and you can call it directly as shown below. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.includes(substring)<\/pre>\n\n\n\n<p>Here are some examples to check if one string contains another. You can use it with literal strings or string variables.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log('good morning'.includes('good'))  \/\/ true<br><br>var a='good morning';<br>var b='good';<br>var res =a.includes(b);<br>console.log(res)   \/\/ true<br><br>var a='good morning';<br>var b='food';<br>var res =a.includes(b);<br>console.log(res)  \/\/ false<br><\/pre>\n\n\n\n<p>In the first example, we check if a literal substring &#8216;good&#8217; is present in another literal string &#8216;good morning&#8217;, which returns true. In second example, we check if one string variable is present in another string, which also returns true. In third case, we get false because the substring &#8216;food&#8217; is not present in the original string.<\/p>\n\n\n\n<p>Includes() function will allow you to directly check if a string contains substring.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_indexOf_function\"><\/span>2. Using indexOf() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>indexOf() function returns the first occurrence of substring in a string. If it is not present then it returns -1. It is also available by default for all string literals and variables. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.indexOf(substring)<\/pre>\n\n\n\n<p>Here is an example to use indexOf().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log('good morning'.indexOf('good'))  \/\/ prints 0<br><br>var a='good morning';<br>var b='good';<br>var res =a.indexOf(b);<br>console.log(res)   \/\/ prints 0<br><br>var a='good morning';<br>var b='food';<br>var res =a.indexOf(b);<br>console.log(res)  \/\/ prints -1<\/pre>\n\n\n\n<p>You can always convert the result of indexOf() into a boolean result by checking the return value of indexOf() in an if conditions as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if('good morning'.indexOf('good')&gt;-1){<br>     console.log(true);<br>}else{<br>     console.log(false);<br>}<br><br>var a='good morning';<br>var b='good';<br>var res =a.indexOf(b);<br>if(res&gt;-1){<br>     console.log(true) <br>}<br>else{<br>     console.log(false) <br>}<\/pre>\n\n\n\n<p>In the above examples, the output is true if the substring is present in original string, else it is false.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_test_function\"><\/span>3. Using test() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Both the above methods work for direct checking of substring within another string. If you want to check the presence or absence of more complex patterns or string variations, then you need to use regular expressions along with test() function. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">regular_expression.test(string);<\/pre>\n\n\n\n<p>Here are some examples to illustrate how this works.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(\/good\/.test(\"good morning\")); \/\/ prints true<br><br><br>var a = \"good morning\";<br>var b = \/good\/;<br>var res = b.test(a);<br><br>console.log(res);  \/\/ prints true<\/pre>\n\n\n\n<p>In the above example, the pattern &#8216;good&#8217; is enclosed in \/&#8230;\/ to define a regular expression. Also, note that the test() function is available for regular expressions and not strings. That is why you call it on the regex pattern and pass the original string as argument.<\/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 3 main ways to check if a substring is present in another string. Using includes() is the most simple and straight forward method to check if a string contains substring. If you need to get the position of a substring in another string, then you can use indexOf(). If you want to check if a complex pattern, not just string, is present in a string, then use test() function with regular expressions.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-property-from-javascript-object\/\">How to Remove Property from JavaScript Object<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-item-from-array-in-javascript\/\">How to Remove Item from Array in JavaScript<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-set-checked-for-checkbox-in-jquery\/\">How to Set Checked for Checkbox in jQuery<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.<\/p>\n","protected":false},"author":1,"featured_media":5407,"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-5391","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 web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.\" \/>\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\/\" \/>\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 web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/\" \/>\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=\"2024-11-05T07:36:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-05T07:43:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/string-contains-substring-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"301\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\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=\"3 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\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Check Whether String Contains Substring in JavaScript\",\"datePublished\":\"2024-11-05T07:36:22+00:00\",\"dateModified\":\"2024-11-05T07:43:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/\"},\"wordCount\":524,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/string-contains-substring-javascript.jpg?fit=301%2C200&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\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/\",\"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\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1\",\"datePublished\":\"2024-11-05T07:36:22+00:00\",\"dateModified\":\"2024-11-05T07:43:37+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1\",\"width\":301,\"height\":200,\"caption\":\"string contains substring in javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-check-whether-string-contains-substring-in-javascript\\\/#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 web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.","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\/","og_locale":"en_US","og_type":"article","og_title":"How to Check Whether String Contains Substring in JavaScript - Ubiq BI","og_description":"Often web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-11-05T07:36:22+00:00","article_modified_time":"2024-11-05T07:43:37+00:00","og_image":[{"width":301,"height":200,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/string-contains-substring-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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Check Whether String Contains Substring in JavaScript","datePublished":"2024-11-05T07:36:22+00:00","dateModified":"2024-11-05T07:43:37+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/"},"wordCount":524,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/string-contains-substring-javascript.jpg?fit=301%2C200&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\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/","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\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1","datePublished":"2024-11-05T07:36:22+00:00","dateModified":"2024-11-05T07:43:37+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often web developers need to check if a given string contains a substring. Here is how to check whether string contains substring in JavaScript.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1","width":301,"height":200,"caption":"string contains substring in javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript\/#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\/2024\/11\/string-contains-substring-javascript.jpg?fit=301%2C200&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1oX","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5391","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=5391"}],"version-history":[{"count":21,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5391\/revisions"}],"predecessor-version":[{"id":5415,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5391\/revisions\/5415"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/5407"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=5391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=5391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=5391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}