432 B
432 B
title, tags
| title | tags |
|---|---|
| initializeArrayWithValues | array,math,intermediate |
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
valto use a default value of0.
const initializeArrayWithValues = (n, val = 0) => Array(n).fill(val);
initializeArrayWithValues(5, 2); // [2, 2, 2, 2, 2]