One short way of doing it would be:

var arr = Array(arraySize).fill(value);

Would make arr = Array [ 0, 0, 0, 0, 0 ] if arraySize == 5 and value == 0, for example.

Answer from Klaus Byskov Pedersen on Stack Overflow
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ Array
Array() constructor - JavaScript - MDN Web Docs
new Array() new Array(element1) new Array(element1, element2) new Array(element1, element2, /* โ€ฆ, */ elementN) new Array(arrayLength) Array() Array(element1) Array(element1, element2) Array(element1, element2, /* โ€ฆ, */ elementN) Array(arrayLength)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-initialize-an-array-in-javascript
How to initialize an array in JavaScript ? - GeeksforGeeks
July 23, 2025 - Initializing an array in JavaScript involves creating a variable and assigning it an array literal. The array items are enclosed in square bracket with comma-separated elements.
๐ŸŒ
Dmitri Pavlutin
dmitripavlutin.com โ€บ javascript-fill-array
How to Fill an Array with Initial Values in JavaScript
October 18, 2021 - Fortunately, you can use the spread operator to transform a sparse array into an array with items initialized with undefined.
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ javascript โ€บ array โ€บ initialize array with values
Initialize a JavaScript array with the specified values - 30 seconds of code
December 26, 2023 - const initializeArrayWithValues = (n, ...vals) => { if (vals.length === 0) return Array(n).fill(0); if (vals.length === 1) return Array(n).fill(vals[0]); return Array.from({ length: n }, (_, i) => vals[i % vals.length]); }; initializeArrayWithValues(5); // [0, 0, 0, 0, 0] initializeArrayWithValues(5, 2); // [2, 2, 2, 2, 2] initializeArrayWithValues(5, 2, 3); // [2, 3, 2, 3, 2] initializeArrayWithValues(3, [2, 3]); // [[2, 3], [2, 3], [2, 3]] ... Discover the inner workings of JavaScript arrays and learn about the different ways to initialize them.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_arrays.asp
JavaScript Arrays
You should use arrays when you want the element names to be numbers. JavaScript has a built-in array constructor new Array().
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ javascript โ€บ array โ€บ array initialization
The many ways to initialize a JavaScript Array - 30 seconds of code
June 18, 2023 - Apart from that, it can easily be "tricked" into creating an array of a given length by passing an object with a length property. This is somewhat slow, but it works well and circumvents some of the problems of the Array() constructor. Additionally, it allows you to pass a mapping function as a second argument, which is very useful for initializing arrays with values.
Find elsewhere
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ how-to-initialize-an-array-in-javascript
How to initialize an array in JavaScript - Altcademy.com
June 9, 2023 - Another way to create and initialize an array is by using the Array constructor. The Array constructor is a built-in JavaScript function that can be used to create new array objects.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ initialize-array-with-values-28395
Mastering Array Initialization in JavaScript | LabEx
Use Array.prototype.fill() to fill it with the desired values. If no value is specified, it defaults to 0. const initializeArrayWithValues = (length, value = 0) => Array(length).fill(value);
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ initialize-array-js
Node.js - Array Initialize - Dot Net Perls
December 13, 2023 - With square brackets, we create empty arrays and arrays with certain elements. This is an ideal syntax for initializing integer and string arrays in JavaScript.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ create-an-array-of-given-size-in-javascript
Create an Array of Given Size in JavaScript - GeeksforGeeks
... // Initialize an array using the apply function let arr = Array.apply(null, Array(5)).map(function (y, i) { return i; }); // Display the length and generated array console.log("Length of the Array:", arr.length); console.log("Array Values: ...
Published: July 23, 2025
๐ŸŒ
Freewebdesigntutorials
freewebdesigntutorials.com โ€บ javaScriptTutorials โ€บ jsArrayObject โ€บ declareAnArray.php
Declare an Array in JavaScript
You will learn to declare arrays both using the JavaScript array constructor [new Array()], and by using the array literal notation. Both declaration methods allow you to simultaneously initialize array elements, as well as array length in the case of the constructor.
๐ŸŒ
Jason Watmore's Blog
jasonwatmore.com โ€บ post โ€บ 2022 โ€บ 12 โ€บ 06 โ€บ javascript-initialize-array-with-conditional-values-or-objects-in-vanilla-js
JavaScript - Initialize Array with Conditional Values or Objects in Vanilla JS | Jason Watmore's Blog
December 6, 2022 - The spread operator (...) can be used to copy the contents of one array into another, if the array being copied is empty nothing is copied into the new array. Using the ternary and spread operators together we can initialize a javascript array with conditional items like this:
๐ŸŒ
Daverhay
daverhay.com โ€บ posts โ€บ javascript โ€บ array-prefill
How to Initialize Sized or Filled Arrays in JavaScript ยท Dave Hay
May 2, 2023 - While you can easily initialize an empty array in JavaScript like, const arr = []. Depending on your project you may find the need to index a pre-sized array. Well look no further!