打赏

lodash map

_.map(collection, [iteratee=_.identity])

创建一个经过 iteratee 处理的集合中每一个元素的结果数组。 iteratee 会传入3个参数:(value, index|key, collection)。 

 

 

<!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>map</title>
    </head>

    <body>
        <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script>
        <script type="text/javascript">
            function square(n) {
                return n * n;
            }

            console.log(_.map([4, 8], square));
            //[16,64]
            var users = [{
                    'user': 'barney'
                },
                {
                    'user': 'fred'
                }
            ];
            console.log(_.map(users, 'user'));
            //['barney','fred']
        </script>
    </body>

</html>

 

posted @ 2018-06-21 17:45  孟繁贵  阅读(2994)  评论(0编辑  收藏  举报
TOP