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>
相關文章
相關標籤/搜索