Utilizor
Contact Us

slice, substring, substr

Extracting parts of a string.

Extracting String Parts

There are 3 methods for extracting a part of a string:

  • slice(start, end)
  • substring(start, end)
  • substr(start, length)

slice()

slice() extracts a part of a string and returns the extracted part in a new string.

The method takes 2 parameters: start position, and end position (end not included).

Example

let text = "Apple, Banana, Kiwi";
let part = text.slice(7, 13); // Banana