JS Array IE does not support the IndexOf method solution

Source: Internet
Author: User

Under IE8, the JS array has no IndexOf method.

Here are the solutions I found:

before using the IndexOf method, execute the following JS, the principle is that if you find that the array has no IndexOf method, this method will be added.


if (! Array.prototype.indexOf)
{
  Array.prototype.indexOf = function (ELT/*, from*/)
  {
    var len = this.length >>> 0;

    var from = number (Arguments[1]) | | 0;
    from = (from < 0)
        ? Math.ceil (from)
        : Math.floor (from);
    if (from < 0)
      from + = Len;

for (; from < Len; from++)
{
if (from in this &&
This[from] = = = ELT)
return from;
}
return-1;
};
}


JS Array IE does not support the IndexOf method solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.