Javascript IE控制台错误:SCRIPT438:对象不存在';t支持属性或方法';从';

Javascript IE控制台错误:SCRIPT438:对象不存在';t支持属性或方法';从';,javascript,jquery,internet-explorer,cross-browser,compatibility,Javascript,Jquery,Internet Explorer,Cross Browser,Compatibility,我在我的网站上有一个函数,它接收电子邮件字符串数组并删除任何重复项。但它在ie上不起作用,因为我使用了Array.from方法。我如何转换成下面的代码来处理ie 让emailslistaray=['reece@gmail.com', 'someone@gmail.com', 'another@gmail.com', 'reece@gmail.com', 'person@gmail.com', 'another@gmail.com']; Array.prototype.unique=函数(){

我在我的网站上有一个函数,它接收电子邮件字符串数组并删除任何重复项。但它在ie上不起作用,因为我使用了Array.from方法。我如何转换成下面的代码来处理ie

让emailslistaray=['reece@gmail.com', 'someone@gmail.com', 'another@gmail.com', 'reece@gmail.com', 'person@gmail.com', 'another@gmail.com'];
Array.prototype.unique=函数(){
返回数组.from(新集合(此));
}
emailslistaray=emailslistaray.unique();
console.log(emailslistaray)

此外,Set方法在ie中没有完全支持,因此您有两种解决方案:

1:只需使用与所有导航器兼容的数组方法:例如,您可以使用以下代码:

Array.prototype.unique = function () {
  return this.reduce(function (acc, el) {
    return acc.indexOf(el) === -1 ? acc.concat(el) : acc;
  }, []);
};
2:将polyfill文件添加到项目中,您可以在此处找到数组的示例。从polyfill:

IE有一个ES5JS引擎,所以几乎没有什么东西可以设置。您必须手动从数组中删除重复项。@Teemu my JS在PHP页面的脚本标记中。我认为你的解决方案对我不起作用,是吗?也许我的评论有点含糊不清,我的意思是“手动”,而不是创建一个
集,自动删除重复项。你可以参考nafaa回答的第一种方法。我已经测试过,它在IE11中工作。原始答案使用IE不支持的箭头函数,我将其转换为ES5语法,然后它与IE 11兼容。