javascript中的lambda表达式

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <script>
        var nubList = [
                {
                    expressId: "00001", //快递单号ID
                    expressNum: "数据1"
                },
                {
                    expressId: "00002", //快递单号ID
                    expressNum: "数据2"
                },
                {
                    expressId: "00003", //快递单号ID
                    expressNum: "数据3"
                },
                {
                    expressId: "00004", //快递单号ID
                    expressNum: "数据4"
                }
            ];

            var nub = nubList.find(nub => nub.expressId == "00002");
            console.log(nub.expressId);
            
            var nub1 = nubList.filter(nub => nub.expressId == "00002");
            console.log(nub1[0].expressId);
    </script>
</body>
</html>

数据来自网上。

find和filter这两个的区别是:

find返回的是一条数据;

filter返回的是一个数组;

posted @ 2018-06-30 13:36  屌丝大叔的笔记  阅读(10973)  评论(0编辑  收藏  举报