# JavaScript String.prototype.substring() Explained with Examples

**URL:** <https://forum.freecodecamp.org/t/javascript-string-prototype-substring-explained-with-examples/15947>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [June 30, 2016, 6:24pm UTC](https://forum.freecodecamp.org/t/javascript-string-prototype-substring-explained-with-examples/15947 "2016-06-30T18:24:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [June 30, 2016, 6:24pm UTC](https://forum.freecodecamp.org/t/javascript-string-prototype-substring-explained-with-examples/15947/1 "2016-06-30T18:24:01Z")

</div>

The `substring()` function _extracts_ a sequence of characters from another given string. It does not alter the original string.

You define the sequence to extract with a _start and end character index_ . These indexes are passed into the `substring()` function as parameters. The substring is formed from the character of the start index all the way to the character of the end index. Both indexes are counted from the beginning of the string, starting from `0` .

Examples:

```auto
"Hello, campers".substring(7, 14);
// output is "campers"

"Hello, world".substring(0, 5);
// output is "Hello"

```

You can also omit the last character index parameter, and the substring sequence will extract from the start index until the end of the string. Example:

```auto
"Hello, campers!".substring(7);
// output is "campers!"

```

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [August 7, 2017, 1:46am UTC](https://forum.freecodecamp.org/t/javascript-string-prototype-substring-explained-with-examples/15947/2 "2017-08-07T01:46:55Z")

</div>

Closed on August 7, 2017, 1:46am UTC


