打赏

lodash 集合处理方法 map和filter区别

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>lodash 集合处理方法 map和filter区别</title>
    </head>

    <body>
        <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script>
        <script type="text/javascript">
            var users = [{
                    'user': 'barney',
                    'age': 36,
                    'active': true
                },
                {
                    'user': 'fred',
                    'age': 40,
                    'active': false
                }
            ];
            //输出 ["barney", "fred"]
            console.log(_.map(users, 'user'))
            // 输出[{    'user': 'barney','age': 36,'active': true},{'user': 'fred','age': 40,'active': false}]
            console.log(_.filter(users, 'user'))
        </script>
    </body>

</html>

 

posted @ 2018-07-13 10:02  孟繁贵  阅读(5723)  评论(0编辑  收藏  举报
TOP