Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→object-flatten-all-arraysnext

object-flatten-all-arrays7.2.0

Merge and flatten any arrays found in all values within plain objects

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — FLATTENALLAR…
  • API — DEFAULTS
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Empty arrays that contain any string value
  • Merge objects in arrays at every nesting level
  • Return a flattened clone without changing the input

Purpose

Recursively traverse the deeply-cloned input and merge all plain objects within each array.

API — flattenAllArrays()

The main function flattenAllArrays() is imported like this:

It’s a function which takes three input arguments:

Input argumentTypeObligatoryDescription
input
Type: Plain object
Obligatory: yes
inputPlain objectyesPlain object to work with.
options
Type: Plain object
Obligatory: no
optionsPlain objectnoOptional Options Object.

The Optional Options Object has the following shape:

KeyTypeDefaultDescription
flattenArraysContainingStringsToBeEmpty
Type: Boolean
Default: false
flattenArraysContainingStringsToBeEmptyBooleanfalseIf any arrays contain strings, flatten them to be empty thing. This is turned off by default, but it’s what you actually need most of the time.

Here are all defaults in one place for copying:

The function will return a clone of the input object, with all arrays flattened.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

API — types

This package is written in TypeScript and exports the following types:

TypeDescription
Obj
Type: Obj
ObjA plain object with string keys and values of any type — what flattenAllArrays() takes and returns.
Opts
Type: Opts
OptsThe Optional Options Object of flattenAllArrays(), documented above.
import type { Obj, Opts } from "object-flatten-all-arrays";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab