filter(Boolean)

注意:0也会过滤

  1. const groceries = ['apple', null, 'milk', undefined, 'bread', '',0];
  2. const cleanList = groceries.filter(Boolean);
  3. console.log(cleanList);
  4. // 'apple', 'milk', 'bread';