indexOf

The "indexOf" method will search one string for the presence of another. For example, if I chose to search the "userAgent" property of the "navigator" object, and I am currently using Internet Explorer 6.x I would be looking at a string that contains "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)". Knowing that the sting should contain "MSIE 6.0" I can ask where the small string is located within the larger string with "indexOf".

var location = navigator.userAgent.indexOf("MSIE 6")

The variable "location" will hold the position of the first letter of the smaller string. In this example the value will be 25 since the computer starts counting at zero, and the smaller string begins at the 26th position of the larger string.

If the smaller string is not contained in the larger string, then "indexOf" will return a value of -1.