ring", 2) function returns the index of the first encountered her occurrence of the specified substring in the original string.In this example, it returns 9. If the occurrence is not found, the indexOf returns -1.Note that this function in the search case sensitive.
lastIndexOf function is used to search for occurrences of a substring in the opposite direction, that is, starting with the last character of the original string value.Syntax lastIndexOf virtually no differences from the above functions - it is also possible to pass two parameters, one of which (the desired substring) is mandatory.The second parameter of this function can indicate the start position of the search and should be counted in the direction from the first to the last character.This feature is also case-sensitive when searching, and returns -1 if the match was not found.Sample: "The original string" .lastIndexOf ("string", 2) This function returns a value of -1, as the search will start from the second position by the end of the string, which will exclude the presence of the text entirely.
function Use Search to search occurrence of a string with a regular expression (regexp).This feature requires only one parameter - the regular expression.The rest of the syntax and return values coincide with the rules for the previous functions.Sample: "The original string" .search (/ string / i) This example also returns the value 9. Of course, the use of regular expressions allows a much more fine-tuning the search, but also require the use of much larger resources of the system, what should not be forgotten when programmingenough intensive scripts.