<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
var data = [{
"Id": "SWE",
"Country": "Sweden",
"Population": 9592552
}, {
"Id": "NOR",
"Country": "Norway",
"Population": 5084190
}];
function display(e) {
alert("E" + e);
var countryData = data.find(function (element, index, array) {
return element.Id === e;
});
alert(countryData.Population);
}
display('SWE');
});
</script>
</head>
</html>
上面发布的代码在 Firefox 和 Chrome 上运行正常,但在 Internet Explorer 中出现错误。错误信息:
Object doesn't support property or method 'find'
最佳答案
这是一个解决方法。您可以使用过滤器而不是查找;但过滤器返回匹配对象的数组。 find
只返回数组中的第一个匹配项。那么,为什么不按以下方式使用过滤器;
data.filter(function (x) {
return x.Id === e
})[0];
关于javascript - "Object doesn' t 在IE中支持属性或方法'find'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37788536/