There are two ways to take advantage of JavaScript functions
1.jQuery
Jquery.inarray (value, array [, FromIndex])
- value type: Anything the value to find.
- Array type: An array of arrays through which to find.
- fromIndex Type: Number array index value that represents where to start the lookup. The default value is 0, which finds the entire array.
$.inArray()
The method is similar to the native .indexOf()
method of JavaScript, which returns 1 when no matching element is found. Returns 0 if the first element of the array matches value
(a parameter) $.inArray()
.
2.indexof
The IndexOf () method returns the position of the first occurrence of a specified string value in a string.
Grammar
Stringobject.indexof (Searchvalue,fromindex)
Parameters |
Description |
Searchvalue |
Necessary. Specifies the string value that needs to be retrieved. |
Fromindex |
An optional integer parameter. Specifies where to start retrieving in the string. Its legal value is 0 to stringobject.length-1. If this argument is omitted, it is retrieved from the first character of the string. |
Description
The method will retrieve the string stringobject from beginning to end to see if it contains substring searchvalue. The location at which to begin retrieving is at the fromindex of the string or at the beginning of the string (when no fromindex is specified). If a searchvalue is found, the position of the first occurrence of the Searchvalue is returned. The character position in Stringobject is starting at 0.
Hints and Notes
Note: the IndexOf () method is case-sensitive!
Note: If the string value that you want to retrieve does not appear, the method returns-1.
JavaScript finds the array for the presence of the specified element