javascript - "Object doesn' t 在IE中支持属性或方法'find'”

标签 javascript c# visual-studio internet-explorer

<!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/

相关文章:

javascript - 如何从 React 组件中向 BODY 添加点击处理程序?

javascript - TinyMCE 和 pluploader 不能一起工作

visual-studio - VS2013 和 Azure - 部署模板验证失败,尽管我既没有编辑模板也没有编辑项目属性

visual-studio - f# 的响应式(Reactive)扩展

c# - 控制台应用程序中的高 CPU 使用率

javascript - Jest 单元测试 - 如何在 setTimeout 重复函数中调用异步函数

javascript - 排序递归函数导致数组的数组

c# - 将图像添加到 ListView 中的第一项?

c# - 使用 ListBox 和 StackPanel 的所有可用空间作为 ItemsPanelTemplate

c# - 如何在 ASP.NET WebAPI 中返回文件 (FileContentResult)