Skip to content

Instantly share code, notes, and snippets.

@fauverism
Created January 11, 2016 14:20
Show Gist options
  • Save fauverism/232863edc68a889d962c to your computer and use it in GitHub Desktop.
Save fauverism/232863edc68a889d962c to your computer and use it in GitHub Desktop.
Creates an array with all falsey values removed.
_.compact(array)
# Ⓢ Ⓝ
Creates an array with all falsey values removed. The values false, null, 0, "", undefined, and NaN are falsey.
Arguments
array (Array): The array to compact.
Returns
(Array): Returns the new array of filtered values.
Example
_.compact([0, 1, false, 2, '', 3]);
// → [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment