Javascript:indexOf
Not working in Internet Explorer?
<script type="text/javascript">
// Cross-browser indexOf
function fakeIndexOf(_array,_obj)
{
if(!_array.indexOf)
{
for(var i=0; i<_array.length; i++)
{
if(_array[i]==_obj){ return i; }
}
return -1;
}
else
{
return _array.indexOf(_obj);
}
}
</script>
- Definition
- indexOf() method finds the first position of a given string (needle) in the searched string. (Returns -1 if the value wasn't found.)
- Syntax
- variable.indexOf(searched_string, start_from [optional])
See also: