QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Remove Falsy Values

Removes falsy values from an array.

  • array
  • falsy
  • filter

Install

npx shadcn@latest add https://quicksnip.dev/r/remove-falsy-values.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

const removeFalsy = (arr) => arr.filter(Boolean);

Usage

const array = [0, 1, false, 2, "", 3, null];
removeFalsy(array); // Returns: [1, 2, 3]