打赏

lodash 移除假值数组 compact

创建一个移除了所有假值的数组。例如:falsenull、 0""undefined, 以及NaN 都是 “假值”.

<!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>移除假值数组</title>
    </head>

    <body>
        <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script>
        <script type="text/javascript">
            var aa = _.compact([0, 1, false, 2, '', 3]);
            console.log(aa);
            //[1,2,3]
        </script>
    </body>

</html>

 

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