Returns a copy of the array with all falsy values removed. In JavaScript, falsenull0,""undefined and NaN are all falsy.

返回的数组将不再包括,false,null,0,"",undefined

1 _.compact([0, 1, false, 2, '', 3]);
2 => [1, 2, 3]

源码:

  _.compact = function(array) {
    return _.filter(array, function(value){ return !!value; });
  }

  

 

 

 

posted on 2012-04-15 22:42  himanhimao  阅读(215)  评论(0编辑  收藏  举报