Indexof method

xiaoxiao2021-04-08  350

The indexof method returns the character position of the first child string in the String object.

Strobj.indexof (Substring [, StartIndex])

Parameter strobj

required. String object or text.

Substring

required. To find the child string in the String object.

Starindex

Optional. This integer value indicates the index of the lookup in the String object. If you omit, look at the beginning of a string.

Note The indexof method returns an integer value indicating the start position of the String object. Returns -1 if the sub-string is found.

If StartIndex is a negative number, StartIndex is used as zero. If it is still larger than the largest character position index, it is treated as the largest possible index.

Perform a lookup from left to right. Otherwise, the method is the same as LastIndexof.

Example The following example illustrates the usage of the INDEXOF method.

Function Indexdemo (str2) {var str1 = "babebibobubabubibobu" var s = str1.indexof (str2); return (s);}

转载请注明原文地址:https://www.9cbs.com/read-132771.html

New Post(0)