{"id":74183,"date":"2022-06-29T14:44:24","date_gmt":"2022-06-29T09:14:24","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/"},"modified":"2025-04-01T00:41:54","modified_gmt":"2025-03-31T19:11:54","slug":"what-is-a-javascript-substring","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/","title":{"rendered":"JavaScript substring() Method: Variants and Uses"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/javascript-tutorial\/\">JavaScript<\/a> provides several methods to manipulate strings, and the substring() method is one of the most commonly used. It allows developers to extract a portion of a string based on specified indices. Understanding how substring() works, along with its variants, can help in efficient string manipulation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-the-substring-method-in-javascript\"><strong>What is the substring() Method in JavaScript?<\/strong><\/h2>\n\n\n\n<p>The substring() method in JavaScript extracts characters from a string between two specified indices. It does not modify the original string but returns the extracted portion as a new string.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring.webp\"><img decoding=\"async\" width=\"1024\" height=\"683\" src=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring-1024x683.webp\" alt=\"What is the substring() Method in JavaScript?\" class=\"wp-image-106461\" style=\"width:952px;height:auto\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring-1024x683.webp 1024w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring-300x200.webp 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring-768x512.webp 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring-150x100.webp 150w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-jubstring.webp 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">string.substring(startIndex, endIndex)<\/pre>\n\n\n\n<p><strong>Parameters:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>startIndex<\/strong> <em>(required)<\/em> \u2013 The starting position of extraction (0-based index).<\/li>\n\n\n\n<li><strong>endIndex<\/strong> <em>(optional)<\/em> \u2013 The position up to (but not including) which characters are extracted. If omitted, the method extracts until the end of the string.<\/li>\n<\/ul>\n\n\n\n<p><strong>Return Value:<\/strong><\/p>\n\n\n\n<p>A new string containing the extracted portion of the original string.<\/p>\n\n\n\n<p class=\"block-course-highlighter\">Understand<a href=\"https:\/\/www.mygreatlearning.com\/blog\/datatypes-in-javascript\/\"> <strong>Datatypes in JavaScript<\/strong><\/a> and how they impact variable behavior, memory usage, and data manipulation in modern web development.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"examples-of-substring-usage\"><strong>Examples of <\/strong><strong>substring()<\/strong><strong> Usage<\/strong><\/h2>\n\n\n\n<p><strong>1. Basic Example<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;JavaScript&quot;;\nlet result = text.substring(0, 4);\nconsole.log(result); \/\/ Output: &quot;Java&quot;\n<\/pre><\/div>\n\n\n<p><strong>2. Omitting the <\/strong><strong>endIndex<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;Hello, World!&quot;;\nlet result = text.substring(7);\nconsole.log(result); \/\/ Output: &quot;World!&quot;\n<\/pre><\/div>\n\n\n<p><strong>3. Swapping Indices<\/strong><\/p>\n\n\n\n<p>If startIndex is greater than endIndex, JavaScript automatically swaps them.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;JavaScript&quot;;\nlet result = text.substring(4, 0);\nconsole.log(result); \/\/ Output: &quot;Java&quot;\n<\/pre><\/div>\n\n\n<p><strong>4. Handling Negative Values<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;Example&quot;;\nlet result = text.substring(-3, 4);\nconsole.log(result); \/\/ Output: &quot;Exam&quot;\n<\/pre><\/div>\n\n\n<p><strong>5. Extracting a Middle Portion of a String<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet sentence = &quot;JavaScript is a powerful language.&quot;;\nlet extracted = sentence.substring(11, 21);\nconsole.log(extracted); \/\/ Output: &quot;is a power&quot;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"substring-vs-slice\"><strong>substring() vs slice()<\/strong><\/h2>\n\n\n\n<p>Both substring() and slice() extract parts of a string, but they have key differences:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Feature<\/strong><\/td><td><strong>substring()<\/strong><\/td><td><strong>slice()<\/strong><\/td><\/tr><tr><td>Handles negative indices<\/td><td>Converts them to 0<\/td><td>Interprets them as offsets from the end<\/td><\/tr><tr><td>Swaps start and end indices<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Modifies original string<\/td><td>No<\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-comparison\"><strong>Example Comparison<\/strong><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;JavaScript&quot;;\nconsole.log(text.substring(-3, 4)); \/\/ Output: &quot;Java&quot;\nconsole.log(text.slice(-3, 4));     \/\/ Output: &quot;&quot;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"practical-applications-of-substring\"><strong>Practical Applications of substring()<\/strong><\/h2>\n\n\n\n<p><strong>1. Extracting a Username from an Email<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet email = &quot;user@example.com&quot;;\nlet username = email.substring(0, email.indexOf(&quot;@&quot;));\nconsole.log(username); \/\/ Output: &quot;user&quot;\n<\/pre><\/div>\n\n\n<p><strong>2. Extracting File Extensions<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet filename = &quot;document.pdf&quot;;\nlet extension = filename.substring(filename.lastIndexOf(&quot;.&quot;) + 1);\nconsole.log(extension); \/\/ Output: &quot;pdf&quot;\n<\/pre><\/div>\n\n\n<p><strong>3. Shortening Strings for Display<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;This is a long string that needs to be shortened.&quot;;\nlet shortText = text.substring(0, 20) + &quot;...&quot;;\nconsole.log(shortText); \/\/ Output: &quot;This is a long strin...&quot;\n<\/pre><\/div>\n\n\n<p><strong>4. Extracting a Domain Name from a URL<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet url = &quot;https:\/\/www.example.com&quot;;\nlet domain = url.substring(url.indexOf(&quot;www.&quot;), url.indexOf(&quot;.com&quot;) + 4);\nconsole.log(domain); \/\/ Output: &quot;www.example.com&quot;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"practice-exercises\"><strong>Practice Exercises<\/strong><\/h2>\n\n\n\n<p>To solidify your understanding, try solving these exercises:<\/p>\n\n\n\n<p><strong>1. Extract the first word from a sentence:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet sentence = &quot;Learning JavaScript is fun!&quot;;\nlet firstWord = sentence.substring(0, sentence.indexOf(&quot; &quot;));\nconsole.log(firstWord); \/\/ Expected output: &quot;Learning&quot;\n<\/pre><\/div>\n\n\n<p><strong>2. Extract the last three characters of a string:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;JavaScript&quot;;\nlet lastThree = text.substring(text.length - 3);\nconsole.log(lastThree); \/\/ Expected output: &quot;ipt&quot;\n<\/pre><\/div>\n\n\n<p><strong>3. Extract the middle part of a string dynamically:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;CodingIsAwesome&quot;;\nlet middlePart = text.substring(3, text.length - 3);\nconsole.log(middlePart); \/\/ Expected output: &quot;ingIsAwe&quot;\n<\/pre><\/div>\n\n\n<p><strong>4. Extract a specific portion of a URL path:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet path = &quot;\/users\/profile\/settings&quot;;\nlet extractedPath = path.substring(path.indexOf(&quot;profile&quot;), path.indexOf(&quot;settings&quot;) - 1);\nconsole.log(extractedPath); \/\/ Expected output: &quot;profile&quot;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The substring() method is a simple yet powerful tool for extracting portions of a string in JavaScript. Understanding its behavior, differences from slice(), and real-world applications can help developers write cleaner and more efficient code.<\/p>\n\n\n\n<p>By leveraging this method appropriately, you can handle string operations with greater flexibility and control.<\/p>\n\n\n\n<p>After mastering JavaScript methods like <code>substring()<\/code>, consider working on real-world <a href=\"https:\/\/www.mygreatlearning.com\/blog\/javascript-projects\/\">JavaScript projects<\/a> to enhance your coding experience.<\/p>\n\n\n\n<p class=\"block-course-highlighter\">To enhance your JavaScript skills, check out the <strong><a href=\"https:\/\/www.mygreatlearning.com\/javascript\/free-courses\">Free JavaScript Courses<\/a><\/strong> offered by Great Learning Academy.<br><br>These courses cover everything from the basics to advanced topics like object-oriented programming and interactive website creation. Enroll now to gain hands-on experience and earn certificates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questionsfaqs\"><strong>Frequently Asked Questions(FAQ\u2019s)<\/strong><\/h2>\n\n\n\n<p><strong>1. Can substring() be used with template literals in JavaScript?<\/strong><br>Yes, you can use substring() with template literals. Since template literals are just strings, you can call .substring() on them like any other string.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet str = `Hello, JavaScript!`;\nconsole.log(str.substring(7, 17)); \/\/ Output: &quot;JavaScript&quot;\n<\/pre><\/div>\n\n\n<p><strong>2. What happens if startIndex and endIndex are the same?<\/strong><br>If startIndex and endIndex are the same, the substring() method returns an empty string.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;Example&quot;;\nconsole.log(text.substring(3, 3)); \/\/ Output: &quot;&quot;\n<\/pre><\/div>\n\n\n<p><strong>3. Is substring() case-sensitive?<\/strong><br>Yes, substring() is case-sensitive because it simply extracts characters without modifying them.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;JavaScript&quot;;\nconsole.log(text.substring(4, 10)); \/\/ Output: &quot;Script&quot; (preserves case)\n<\/pre><\/div>\n\n\n<p><strong>4. Can substring() be chained with other string methods?<\/strong><br>Yes, substring() can be chained with other string methods like toUpperCase() or trim().<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet text = &quot;  Hello, JavaScript!  &quot;;\nlet result = text.substring(2, 14).trim().toUpperCase();\nconsole.log(result); \/\/ Output: &quot;HELLO, JAVASC&quot;\n<\/pre><\/div>\n\n\n<p><strong>5. Does substring() work with non-English characters or emojis?<\/strong><br>Yes, but it treats each Unicode character as a single unit, which may lead to unexpected results with emojis or special characters.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet emojiString = &quot;Hello \ud83d\ude0a World!&quot;;\nconsole.log(emojiString.substring(6, 8)); \/\/ Output: &quot;\ud83d\ude0a &quot; (May not work as expected with multi-byte characters)\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>The substring() method in JavaScript extracts parts of a string between specified indices. This article explores its syntax, usage, key differences from similar methods like slice(), and practical applications such as extracting usernames or file extensions. Try hands-on exercises to master string manipulation.<\/p>\n","protected":false},"author":41,"featured_media":106460,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36840],"content_type":[],"class_list":["post-74183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-javascript"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript substring() Method: Variants and Uses<\/title>\n<meta name=\"description\" content=\"Learn about JavaScript&#039;s substring() method, its variants, syntax, examples, and practical applications for efficient string manipulation in web development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript substring() Method: Variants and Uses\" \/>\n<meta property=\"og:description\" content=\"Learn about JavaScript&#039;s substring() method, its variants, syntax, examples, and practical applications for efficient string manipulation in web development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-29T09:14:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-31T19:11:54+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1117\" \/>\n\t<meta property=\"og:image:height\" content=\"585\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\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:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"JavaScript substring() Method: Variants and Uses\",\"datePublished\":\"2022-06-29T09:14:24+00:00\",\"dateModified\":\"2025-03-31T19:11:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/\"},\"wordCount\":535,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/javascript-substring-banner.jpg\",\"keywords\":[\"javascript\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/\",\"name\":\"JavaScript substring() Method: Variants and Uses\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/javascript-substring-banner.jpg\",\"datePublished\":\"2022-06-29T09:14:24+00:00\",\"dateModified\":\"2025-03-31T19:11:54+00:00\",\"description\":\"Learn about JavaScript's substring() method, its variants, syntax, examples, and practical applications for efficient string manipulation in web development.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/javascript-substring-banner.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/javascript-substring-banner.jpg\",\"width\":1117,\"height\":585},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/what-is-a-javascript-substring\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript substring() Method: Variants and Uses\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript substring() Method: Variants and Uses","description":"Learn about JavaScript's substring() method, its variants, syntax, examples, and practical applications for efficient string manipulation in web development.","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:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript substring() Method: Variants and Uses","og_description":"Learn about JavaScript's substring() method, its variants, syntax, examples, and practical applications for efficient string manipulation in web development.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2022-06-29T09:14:24+00:00","article_modified_time":"2025-03-31T19:11:54+00:00","og_image":[{"width":1117,"height":585,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"JavaScript substring() Method: Variants and Uses","datePublished":"2022-06-29T09:14:24+00:00","dateModified":"2025-03-31T19:11:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/"},"wordCount":535,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg","keywords":["javascript"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/","url":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/","name":"JavaScript substring() Method: Variants and Uses","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg","datePublished":"2022-06-29T09:14:24+00:00","dateModified":"2025-03-31T19:11:54+00:00","description":"Learn about JavaScript's substring() method, its variants, syntax, examples, and practical applications for efficient string manipulation in web development.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg","width":1117,"height":585},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/what-is-a-javascript-substring\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"JavaScript substring() Method: Variants and Uses"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg",1117,585,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-300x157.jpg",300,157,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-768x402.jpg",768,402,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-1024x536.jpg",1024,536,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg",1117,585,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner.jpg",1117,585,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-640x585.jpg",640,585,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/javascript-substring-banner-150x79.jpg",150,79,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"The substring() method in JavaScript extracts parts of a string between specified indices. This article explores its syntax, usage, key differences from similar methods like slice(), and practical applications such as extracting usernames or file extensions. Try hands-on exercises to master string manipulation.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/74183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=74183"}],"version-history":[{"count":45,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/74183\/revisions"}],"predecessor-version":[{"id":109843,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/74183\/revisions\/109843"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/106460"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=74183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=74183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=74183"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=74183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}