The `build-array` package provides a minimalist utility for programmatically creating arrays of a specified `length`, optionally pre-filled with a given `value`. Currently stable at version 1.0.0, this package is likely in a maintenance state, receiving updates only for critical bug fixes if any, due to its straightforward and complete functionality. It offers a lightweight alternative to more verbose patterns like `new Array(length).fill(value)`, particularly useful in environments or coding styles where brevity and explicit initialization are preferred. Its primary differentiator is its single-function API, simplifying array creation and initial population without requiring chained methods or polyfills for older `Array.prototype.fill` behavior.
npm install build-arrayVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `build-array` to create arrays of various lengths, with and without initial fill values, and highlights a key behavior when filling with object references.
If independent objects are required for each array element, iterate over the created array and assign new object instances (e.g., `Array(length).map(() => ({...template}))`).For new projects targeting modern JavaScript environments, consider native methods like `Array(length).fill(value)` or `Array.from({ length }, () => value)` which offer similar functionality and are widely supported.For CommonJS, use `const buildArray = require('build-array');`. For ES Modules, use `import buildArray from 'build-array';`. Ensure your environment supports the chosen module system.Ensure the first argument passed to `buildArray` is a non-negative integer. Use nullish coalescing (e.g., `length ?? 0`) or type checking if the length might be dynamic or optional.
No dependency data recorded yet.