Elysia Tools

Browse tools, examples, visual explainers, and topic guides from one clear workspace.

Top Categories

Hubs

Language
ZHESPTRUFRDEEN

Elysia Tools

Navigation

Data Processing

Compact Array

· Last updated:2026-01-21

Remove falsey values from array using lodash _.compact

Details

What this tool helps you do

Array Compaction Tool

This tool removes falsey values from arrays using Lodash's _.compact method.

Falsey values removed:

  • false
  • null
  • 0
  • "" (empty string)
  • undefined
  • NaN

Example:

Input:  [0, 1, false, 2, "", 3, null, 4, undefined, 5, NaN]
Output: [1, 2, 3, 4, 5]

Options:

  • Preserve Zeros: Keep zero values in the array
  • Preserve Empty Strings: Keep empty strings in the array

Execution

Run this tool

Fill in the form, run the tool, and review the result in one place.

Samples

Examples that match this tool

Related

Continue with connected tools and hubs

Written by the Elysia Tools team
Data Processing130
Array60
Lodash53

Tool usage guide

Learn when to use this tool, what it supports, and how real users apply it.

Key facts

Category
Data Processing
Input types
textarea, checkbox
Output type
text
Sample coverage
4
API ready
Yes

Overview

The Compact Array tool removes falsey values from JSON arrays using Lodash's _.compact method. It cleans data by eliminating false, null, 0, empty strings, undefined, and NaN, with options to preserve zeros and empty strings if needed.

When to use

  • When you have an array with mixed data types and need to filter out invalid or empty entries.
  • Before performing data analysis or visualization to ensure only meaningful values are included.
  • When cleaning user input or API responses that may contain falsey values.

How it works

  1. 1Enter a valid JSON array into the input field.
  2. 2Optionally, check 'Preserve Zeros' to keep zero values or 'Preserve Empty Strings' to keep empty strings.
  3. 3Click the compact button to generate a new array with falsey values removed.
  4. 4The output is displayed as a JSON array ready for use.

Use cases

  • Cleaning data arrays from databases or APIs for further processing.
  • Preprocessing arrays in data pipelines to remove noise and invalid entries.
  • Simplifying JavaScript arrays by eliminating unnecessary falsey values.

Compare alternatives

  • Limit numerical values to specified ranges by clipping, filtering, or marking out-of-bounds values.

  • Extract all keys from JSON objects with multiple output formats.

  • Remove BOM (Byte Order Mark) characters from text and file content.

Who it's for

Best for

  • Convert content in the browser.
  • Repeatable jobs with content and the same settings every time.
  • Jobs where the output is plain text.

Not ideal for

  • Fully automated batch jobs — this page is built for interactive use; use the API endpoint for scripts.
  • Content in other formats — this tool expects content.

Edge cases & common failures

  • Very large files

    Large files take longer and can hit browser memory limits — try a smaller sample first.

  • Skipping the output check

    Compare the first rows or pages of the output with the input before using it in production.

  • Files from unusual exporters

    Some files use format variants that do not convert cleanly — if the output looks wrong, re-save the file from the app that created it and try again.

Examples

1. Clean a Mixed Data Array

Background

A developer has an array from a JSON response containing numbers, booleans, and nulls.

Problem

The array has falsey values that interfere with calculations.

How to use

Input the array [0, 1, false, 2, "", 3, null, 4, undefined, 5, NaN] and click compact.

Outcome

The output is [1, 2, 3, 4, 5], with all falsey values removed.

2. Preserve Zeros in Sensor Data

Background

An IoT application logs temperature readings where zero is a valid value indicating freezing point.

Problem

Need to remove nulls and undefined values but keep zeros for accurate analysis.

How to use

Input the array [23, null, 0, 15, undefined, 0, 12] and check 'Preserve Zeros' before compacting.

Outcome

The output is [23, 0, 15, 0, 12], with zeros retained and other falsey values removed.

FAQ

What falsey values are removed?

The tool removes false, null, 0, empty strings, undefined, and NaN.

Can I keep zero values in the array?

Yes, enable the 'Preserve Zeros' option to retain zeros.

How do I preserve empty strings?

Check the 'Preserve Empty Strings' option before compacting.

What input format is required?

The input must be a valid JSON array, e.g., [1, null, 2, false, 3].

Is the output a new array?

Yes, the tool returns a new array with falsey values removed, leaving the original unchanged.

Home
Tools3208
Samples593
Visualizations469
Viewers103
Hubs237
Tags333
Images, Audio & Video657

Image, audio, and video processing, conversion, and optimization tools

Math, Date & Finance646

Calculators, numerics, date logic, statistics, and finance tools

Design & Color298

Color, layout, graphics, visual styling, and design helper tools

Text & Writing209

Writing, cleanup, formatting, extraction, and text analysis tools

Developer & Web193

Developer utilities, networking, web debugging, and automation helpers

Conversion & Encoding175

Format, file, archive, unit, and encoding conversion tools

Private Habit Records: Backup, Restore and Sharing Review
Article to X and LinkedIn Drafts: Fact Review and Handoff
Markdown Interactive Deck Review and Offline Handoff
Small-Room Furniture Layout Review and Move-In Handoff
FLAC/WAV Source Screening and Evidence Handoff

© 2026 Elysia Tools. All rights reserved.

DocsPricingAboutTerms of ServicePrivacy PolicyCookiesContact
Observability

Distributed Tracing Samples

Comprehensive distributed tracing examples using Jaeger, OpenTelemetry, and other modern observability tools for microservices architecture

Security

JWT Samples

Comprehensive JWT examples from basic token structure to advanced security implementations

Document

PDF Samples

Generated PDF samples from tools dated 2026-02-01 to 2026-02-10

Web Technologies

WebRTC Real-Time Communication Samples

Comprehensive WebRTC samples for peer-to-peer audio/video communication, data channels, screen sharing, and signaling server implementation

Data Processing

BOM Character Remover

Remove BOM (Byte Order Mark) characters from text and file content. Perfect for cleaning up text files that have encoding issues, fixing CSV imports, and preparing data for processing. Features: - Detect and remove UTF-8 BOM (EF BB BF) - Detect and remove UTF-16 BOM (FE FF or FF FE) - Detect and remove UTF-32 BOM (00 00 FE FF or FF FE 00 00) - Support multiple input formats - Visual BOM character display - Detailed detection report - Support for batch text processing Common Use Cases: - Fix CSV file import errors - Clean up text file encoding issues - Prepare data for JSON parsing - Fix XML parsing problems - Resolve API data encoding conflicts - Standardize text data format

Data Processing

Data Range Limiter

Limit numerical values to specified ranges by clipping, filtering, or marking out-of-bounds values. Perfect for data quality control, sensor data cleaning, business rule enforcement, and data preprocessing. Features: - Range clipping (clip values to min/max boundaries) - Range filtering (remove out-of-bounds rows) - Range marking (flag modified values) - Per-column range configuration - Automatic numeric column detection - Multiple handling strategies - Detailed modification reports - Statistical analysis of changes - Business rule enforcement Common Use Cases: - Sensor data validation and cleaning - Machine learning input preparation - Data quality control and validation - Business constraint enforcement - Outlier management and control - Data preprocessing pipelines

Data Processing

JSON Key Extractor

Extract all keys from JSON objects with multiple output formats. Perfect for analyzing JSON structure, documentation generation, and understanding complex nested objects.

Data Processing

Pull Values

Remove specific values from an array using lodash _.pull

Data Range Limiter
JSON Key Extractor
BOM Character Remover