JavaScript Substr

substr() returns a portion of a string starting at a given index and spanning a given length. It is a legacy method — prefer slice() in new code — but you will still meet it in the wild.

Syntax

str.substr(start, length)

Examples

Input Arguments Output
"hello" 1, 3 "ell"

Gotchas

  • substr() is deprecated. Use slice() or substring() instead.

Try it live

Type your input and see Substr transform it instantly.

Description: Extracts a portion of a string starting from the start index with a specified length.

Example: 'pancakes'.substr(0, 3) => 'pan'

Want to go further? Chain Substr with other functions in the visual Playground — pipe one output into the next and watch your data transform.

Related functions

© 2026 Heifara Buval