insert (JavaScript)
Inserts a substring.
Defined in
String (Standard - JavaScript)Syntax
insert(substr:string, index:int) : stringParameters | Description |
---|---|
substr | The substring to be inserted. |
index | The index before which the insertion occurs. A value less than or equal to 0 means the beginning of the string. A value greater than the last index means the end of the string. |
count | The number of characters of the substring to be inserted. Defaults to the entire substring. |
Return value | Description |
---|---|
string | A copy of this string with the substring inserted. This string remains as is. |
Examples
(1) This example inserts Moscow in the middle of Paris Tokyo.var cities = new String("Paris Tokyo");
cities = cities.insert("Moscow ", 8);
return "cities = " + cities.valueOf()
(2) This example does the same.
var cities = new String("Paris Tokyo");
cities = cities.insert("Moscow Tokyo", 8, 9);
return "cities = " + cities.valueOf()