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

String.prototype.substring() β€” basic substring

πŸ“– 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()

str.substring(start, end) returns the characters from index start up to (not including) end.

Challenge: Implement extractSub(str) that extracts characters from index 1 to 4.

extractSub('abcdef') // β†’ 'bcd'
πŸ’‘ Hints (1)
  • β€’ `str.substring(1, 4)` returns characters at indices 1, 2, and 3.