Skip to content

Files

Latest commit

931e9c6 · Jan 5, 2018

History

History
14 lines (10 loc) · 383 Bytes

initializeArrayWithValues.md

File metadata and controls

14 lines (10 loc) · 383 Bytes

initializeArrayWithValues

Initializes and fills an array with the specified values.

Use Array(n) to create an array of the desired length, fill(v) to fill it with the desired values. You can omit val to use a default value of 0.

const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
initializeArrayWithValues(5, 2); // [2,2,2,2,2]