JS Built-ins
← String139 / 195
StringString.prototype.substringbeginner

String.prototype.substring() β€” omit end goes to end of string

πŸ“– Usage Example
const str = 'Hello, World!'
str.substring(7, 12)   // β†’ 'World'
str.substring(5, 2)    // β†’ 'llo' (args swapped)
str.substring(7)       // β†’ 'World!'

Use substring() to extract characters between two indices, automatically swapping them if start is greater than end.

String.prototype.substring() β€” Omitting End

If you omit the second argument, .substring() goes to the end of the string.

Challenge: Implement fromStart(str, n) that returns everything from index n to the end.

fromStart('hello world', 6) // β†’ 'world'
πŸ’‘ Hints (1)
  • β€’ `str.substring(n)` is equivalent to `str.substring(n, str.length)`.