Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
File

title: fillArray tags: array,math,intermediate

TS JS Deno

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 fillArray = (n: number, val: any = 0) => Array(n).fill(val);
fillArray(5, 2); // [2, 2, 2, 2, 2]