mid (JavaScript)

Gets a substring starting at a specified position.

Defined in

String (Standard - JavaScript)

Syntax

mid(pos:int) : string

mid(pos:int, count:int) : string

Parameters Description
pos The beginning index, inclusive, where 0 is the first index in a string.
count The number of characters to get. Defaults to the rest of the string.
Return value Description
string The substring.

Usage

This method gets characters starting at the index specified by parameter 1.

Examples

(1) This example returns Moscow Tokyo (index 8 to the end).
cities = new String("Paris   Moscow   Tokyo");
cities.mid(8)

(2) This example returns Moscow (index 8 for 6 characters).

cities = new String("Paris   Moscow   Tokyo");
cities.mid(8, 6)