Socket
Socket
Sign inDemoInstall

flatten

Package Overview
Dependencies
0
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    flatten

Flatten arbitrarily nested arrays into a non-nested list of non-array items. Maintained for legacy compatibility.


Version published
Weekly downloads
2.5M
decreased by-18.84%
Maintainers
3
Install size
4.40 kB
Created
Weekly downloads
 

Package description

What is flatten?

The flatten npm package is designed to flatten nested arrays or objects into a single level, making it easier to work with complex data structures. It provides a straightforward and efficient way to reduce the depth of data structures for easier processing and manipulation.

What are flatten's main functionalities?

Flattening arrays

This feature allows you to flatten nested arrays into a single-level array. For example, if you have an array like [[1, 2], [3, 4]], using flatten will result in [1, 2, 3, 4].

[].concat.apply([], array)

Flattening objects

This feature is for flattening nested objects into a single-level array or object, depending on the implementation. It's useful for when you need to simplify the structure of deeply nested objects.

Object.keys(obj).reduce(function(acc, key) { return acc.concat([{key: obj[key]}]); }, [])

Other packages similar to flatten

Readme

Source

flatten

A tiny utility to flatten arrays of arrays (of arrays, etc., recursively, infinitely or to an optional depth) into a single array of non-arrays.

example:

> var flatten = require('flatten');
undefined
> flatten([1, [2, 3], [4, 5, 6], [7, [8, 9]], 10])
[ 1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10 ]
> flatten([1, [2, [3, [4, [5]]]]], 2)
[ 1,
  2,
  3,
  [ 4, [ 5 ] ] ]

install:

npm install flatten

license:

MIT/X11.

Keywords

FAQs

Last updated on 31 Oct 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc