Files
30-seconds-of-code/snippets/filterFalsy.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

320 B
Executable File

title, tags
title tags
filterFalsy array,beginner

Filters out the falsy values in an array.

Use Array.prototype.filter() to get an array containing only truthy values.

const filterFalsy = arr => arr.filter(Boolean);
filterFalsy(['', true, {}, false, 'sample', 1, 0]); // [true, {}, 'sample', 1]