Version: v0.8.1 - Beta.  We welcome contributors & feedback.

String.substring

substring($startIndex, { numChars|toIndex }) -> string

Description

Get the inner string beginning at $startIndex.

The second argument is a Map that can define either numChars or toIndex.

If neither is defined, it returns the rest of the string.

'abcdef'.substring(4)
//= 'def'

'abcdef'.substring(4, { numChars: 2 })
//= 'de'

'abcdef'.substring(2, { toIndex: 5 })
//= 'bcde'

Negative Indexes

If $startIndex or toIndex are negative, it counts from the end of the string.

'abcdef'.substring(-2, { numChars: 2 })
//= 'ef'

'abcdef'.substring(-3, { toIndex: -1 })
//= 'def'

See Also