prefill-array
v1.0.4
Published
Prefill an array with values
Downloads
9
Readme
prefill-array
Prefill an array with values.
Install
Install prefill-array
using npm:
npm install --save prefill-array
Or via yarn:
yarn add prefill-array
Usage
const prefill = require('prefill-array');
const leet = prefill(5, 1337);
console.log(leet);
// → [ 1337, 1337, 1337, 1337, 1337 ]
const recursive = prefill(4, prefill(2, '2D'));
console.log(recursive);
// → [ [ '2D', '2D' ], [ '2D', '2D' ], [ '2D', '2D' ], [ '2D', '2D' ] ]
Syntax
const newArray = prefill(number, value);
Parameters
number
Number of elements to insert. Must be greater than or equal to zero.
value
Value to use for filling.
Return value
Returns the filled array.
License
MIT