Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 897 Bytes

substr.md

File metadata and controls

38 lines (29 loc) · 897 Bytes

substr(string, start, length)

Source

Extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters. The substr() does not change the original string.

Custom Needs

Validate string type for preventing SyntaxError

Since

1.0.0

Category

String

Arguments

{String} string - The string to extract
{Number} start - The position where to start the extraction. First character is at index 0
{Number?} length - Optional. The number of characters to extract. If omitted, it extracts the rest of the string

Returns

{String} Returns extract part of a string

Example

substr('Hello World!', 0, 5)
// => 'Hello'
substr({}, 0, 5)
// => {}
substr('Hello World!', 6)
// => 'World!'