怎樣在js的數組中過濾掉false, null, 0, "", undefined, and NaN這些值

來源:互聯網
上載者:User
這次給大家帶來怎樣在js的數組中過濾掉false, null, 0, "", undefined, and NaN這些值,在js的數組中過濾掉false, null, 0, "", undefined, and NaN這些值的注意事項有哪些,下面就是實戰案例,一起來看一下。

對於 false,null,0,undefiend,NaN直接取!得到的都是true,因此這裡只需要在判斷Null 字元串"";

function bouncer(arr) {  // Don't show a false ID to this bouncer.  return arr.filter(function(val){    return !(!val || val === "");  });}

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

相關閱讀:

如何判斷瀏覽器的IE 6 7 8 9

怎麼解決IE11的textarea不換行這個BUG

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.