Array Flatten Utility

1.0.0 · abandoned · verified Sun Apr 19

The `utils-flatten` package provides a single, straightforward utility function for recursively flattening arrays in JavaScript. It is a minimal, focused library for transforming deeply nested arrays into a single-level array. The package is currently at version 1.0.0 and appears to be an unmaintained or abandoned project, with its last known activity dating back to around 2013, as indicated by the copyright and build status badge. Its primary differentiation, if any, lies in its extreme simplicity and small footprint, predating the widespread adoption of native `Array.prototype.flat()` in modern JavaScript environments (ES2019+). Developers should be aware that contemporary JavaScript offers built-in alternatives, making this package largely redundant for new projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the `flatten` function using CommonJS and use it to flatten a deeply nested array.

const flatten = require('utils-flatten');

const nestedArray = ['one', ['two', ['three', 'four'], 'five'], 6, [7, [8]]];

const flattenedArray = flatten(nestedArray);

console.log('Original array:', nestedArray);
console.log('Flattened array:', flattenedArray);
// Expected output: ['one', 'two', 'three', 'four', 'five', 6, 7, 8]

const anotherNestedArray = [1, [2, [3, 4], 5], [6, [7, [8, 9]]]];
const fullyFlattened = flatten(anotherNestedArray);
console.log('Another original array:', anotherNestedArray);
console.log('Fully flattened array:', fullyFlattened);

view raw JSON →