I have used indexOf to check whether i have particular text is present in a sentence or not like the following
var temp = "";
temp="data not available";
if(temp.indexOf("datas") == 0){
alert("True");
}
else{
alert("false");
}
The problem i was facing is indexOf is not supported in Internet Explorer 8. How to perform this operation in IE8 too? Is there any default alternate functions available in jquery?
I tried inArray but it supports only array.
fiddle
I have used indexOf to check whether i have particular text is present in a sentence or not like the following
var temp = "";
temp="data not available";
if(temp.indexOf("datas") == 0){
alert("True");
}
else{
alert("false");
}
The problem i was facing is indexOf is not supported in Internet Explorer 8. How to perform this operation in IE8 too? Is there any default alternate functions available in jquery?
I tried inArray but it supports only array.
fiddle
Share Improve this question edited Feb 14, 2014 at 6:39 Pandiyan Cool asked Feb 14, 2014 at 6:29 Pandiyan CoolPandiyan Cool 6,5658 gold badges52 silver badges90 bronze badges 8- add it as given – Grijesh Chauhan Commented Feb 14, 2014 at 6:31
- One of solution is given here, developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – Adil Commented Feb 14, 2014 at 6:33
- you can find answer in so stackoverflow./questions/9768574/… – Raja Jaganathan Commented Feb 14, 2014 at 6:34
- @RC. This is not duplicate am asking for string not for array and also am asking whether any default function available or not. – Pandiyan Cool Commented Feb 14, 2014 at 6:37
- stackoverflow./questions/1744310/… – Prashobh Commented Feb 14, 2014 at 6:39
2 Answers
Reset to default 14I think you're confused about which indexOf()
is supported.
You're using String.prototype.indexOf()
, which is supported from IE6 onwards, according to Microsoft's documentation.
It's Array.prototype.indexOf()
that's only supported from IE9 onwards.
You can use String.search
:
var temp = "data not available";
if(!temp.search("datas")){
alert("True");
} else {
alert("false");
}
Fiddle
(NB: I don't have IE8 to test it)