packed-array
Social Media Photo by Elevate on Unsplash
An utility to create fast, non-holey arrays.
;const packedArray = ; // via unpkg, as global utility// <script src="https://unpkg.com/packed-array">
API
This utility has the exact same Array.from API, except the first parameter can be an integer, as length
, and the second one can be just a static value, to fill the Array of specified length
with such value.
const array = ;
Goal
Simplify the creation of arrays extremely fast to be looped or consumed within their length
boundaries.
Native Alternative
If you're after just arrays with a length and some initial value, the following would likely perform better, producing the same result:
// note the Array(length) is mandatory to obtain a packed kindconst array = Array;