No Support For Indexof In Ie 8?
I have a requirement where I create radio buttons dynamically based upon JSON response. So far what I did works in Chrome and firefox, but gives Object doesn't support this propert
Solution 1:
IE versions < 9 don't have indexOf
, so you can add your own:
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (elt /*, from*/) {
var len = this.length >>> 0;
varfrom = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0) from += len;
for (; from < len; from++) {
if (frominthis && this[from] === elt) returnfrom;
}
return -1;
};
}
var subItem = [];
subItem[1]="CSMTestPWXListinerService,CSMTestPWXListinerService_ManualyAdded";
console.log(subItem[1].indexOf(","));
//returns 25
Solution 2:
According to http://msdn.microsoft.com/en-us/library/ie/53xtt423(v=vs.94).aspx
MS has said that it support indexof() to IE8 as well!
Solution 3:
What happens if you do this instead?:
if(temp.indexOf(",") >= 0)
I know I've had cases where it seemed to not understand what the object type was when reference from an array instead of a variable created from the contents of that array location. It doesn't make sense that this would be the case, but I've used it as a workaround before.
Post a Comment for "No Support For Indexof In Ie 8?"