配列から空要素を削除する方法について解説します。 この記事のポイント 配列の要素が空か判断するときはBooleanコンストラクタ関数を使うと便利 filterメソッドで配列に残す要素の条件を指定できる 配列から空要素だけ削除 配列にある空要素を一括で削除するときはfilterメソッドを実行します。 以下の例では、空要素を含む配列が入っている変数testに対してfilterメソッドを使って空要素を削除します。 JS コード例 let test = [ 'cat', 'dog', null, ,'penguin', false, undefined, 0, 'lion']; let clean = test.filter(Boolean); console.log(clean); // (4) ["cat", "dog", "penguin", "lion"] filterメソッドには要素を削