1) To create new array which, you cannot iterate over, you can use array constructor:

Array(100) or new Array(100)


2) You can create new array, which can be iterated over like below:

a) All JavaScript versions

  • Array.apply: Array.apply(null, Array(100))

b) From ES6 JavaScript version

  • Destructuring operator: [...Array(100)]
  • Array.prototype.fill Array(100).fill(undefined)
  • Array.from Array.from({ length: 100 })

You can map over these arrays like below.

  • Array(4).fill(null).map((u, i) => i) [0, 1, 2, 3]

  • [...Array(4)].map((u, i) => i) [0, 1, 2, 3]

  • Array.apply(null, Array(4)).map((u, i) => i) [0, 1, 2, 3]

  • Array.from({ length: 4 }).map((u, i) => i) [0, 1, 2, 3]

Answer from stpoa on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › article › create-empty-array-of-a-given-size-in-javascript
Create empty array of a given size in JavaScript
March 15, 2026 - Array.from(): [ undefined, undefined, undefined, undefined ] With fill(0): [ 0, 0, 0 ] Spread operator: [ undefined, undefined, undefined ] Use new Array(size) for basic empty arrays, or Array.from({length: size}) when you need to iterate ...
Discussions

javascript create empty array of a given size - Stack Overflow
in javascript how would I create an empty array of a given size Psuedo code: X = 3; createarray(myarray, X, ""); output: myarray = ["","",""] More on stackoverflow.com
🌐 stackoverflow.com
Can you declare an array of unknown size in Javascript?
Will it expand as it gets filled up with elements, or would you just have to create a very large array that would be more than enough size for any data you might want. ... Yes. Simply create an empty array: ... Then you can add more elements dynamically by specifying any index (your array can even have "gaps" in it, an 'undefined' elements): ... The elements in an array may not be of the same type. As you can see, arrays in JavaScript ... More on teamtreehouse.com
🌐 teamtreehouse.com
3
October 24, 2014
How to initialize an array's length in JavaScript? - Stack Overflow
Most of the tutorials that I've read on arrays in JavaScript (including w3schools and devguru) suggest that you can initialize an array with a certain length by passing an integer to the Array More on stackoverflow.com
🌐 stackoverflow.com
How to initialize empty array of objects?
const arr: {name: string}[] = [] Maybe like this? More on reddit.com
🌐 r/typescript
14
18
May 27, 2021
🌐
Medium
allaboutcode.medium.com › javascript-how-to-create-and-fill-an-empty-array-with-a-given-size-ed6954355a5f
JavaScript — How to create and fill an empty array with a given size? - Marika Lam - Medium
November 17, 2022 - JavaScript — How to create and fill an empty array with a given size? Solution const arr = Array(5).fill(""); console.log(arr); //prints out ["","","","",""] console.log(arr[0]); //prints out "" 1) …
🌐
EyeHunts
tutorial.eyehunts.com › home › create empty array javascript with size | example code
Create empty array JavaScript with size | Example code
June 5, 2023 - In the code snippet above, the fill("") method is used to populate each item in the array with an empty string. You can replace "" with any other value you want to initialize the array with.
🌐
xjavascript
xjavascript.com › blog › javascript-create-empty-array-of-a-given-size
How to Create an Empty Array with a Given Size in JavaScript (Filled with Empty Strings) — xjavascript.com
For example, arr.join(',') with empty strings returns ",,,," (useful for placeholders), whereas undefined would return "undefined,undefined,...". Explicit Intent: An empty string clearly signals "no value yet" rather than "missing" (undefined) or "invalid" (null). Below are the most reliable methods to create an array of a specified size filled with empty strings.
🌐
C# Corner
c-sharpcorner.com › blogs › initializing-empty-arrays-in-javascript1
Initializing Empty Arrays in JavaScript
It initializes the array with the number of elements equal to the number of commas used inside square brackets []. So in the above case, the array's length will be 2 instead of 3. var arr1 = [,,]; var arr2 = [,,,]; console.log(arr1.length); //logs 2 console.log(arr2.length); //logs 3 · And in the above example, we used the length property to iterate the array. It loops 2 times instead of 3. ... Well, arrays are dynamic in javascript; they can grow and shrink according to our requirements.
Find elsewhere
🌐
sebhastian
sebhastian.com › create-empty-array-javascript
Create empty array with JavaScript | sebhastian
May 31, 2021 - Both the array literal notation and the array constructor produce the same thing. Finally, you can also create an empty array by setting the length property of your array into 0.
🌐
Code Like A Girl
code.likeagirl.io › create-an-array-of-empty-arrays-7ec77edea546
How to create an array of empty arrays | by Ai-Lyn Tang | Code Like A Girl
June 25, 2019 - For two exercises in exercism.io (Matrix and Pascal’s Triangle), I have wanted to create an array of empty arrays. There are lots of ways…
🌐
Quora
quora.com › How-do-you-declare-an-empty-array-in-JavaScript
How to declare an empty array in JavaScript - Quora
Answer (1 of 19): You have two main ways to go: simple declaration with square brackets. const myArray = [] Or instantiation of the Array Object using the constructor method: const myArray = new Array() The trendy kids favor the first way, nowadays, with the empty square brackets, but if you h...
🌐
Arnab Ghosh
blog.arnabghosh.me › javascript-create-empty-array
How to Create an Empty Array in JavaScript? [2 ways]
November 27, 2022 - Create a new empty array. const sampleArr = [] Push an empty object inside the array. sampleArr.push(new Object()) If you want to add multiple empty objects inside an empty array, you can use a for-loop. const n = 50; For (i = 0; i < n; i++){ ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › fill
Array.prototype.fill() - JavaScript - MDN Web Docs
const arr = new Array(3); for (let i = 0; i < arr.length; i++) { arr[i] = new Array(4).fill(1); // Creating an array of size 4 and filled of 1 } arr[0][0] = 10; console.log(arr[0][0]); // 10 console.log(arr[1][0]); // 1 console.log(arr[2][0]); // 1 · This example shows how to populate an array, setting all elements to a specific value. The end parameter does not have to be specified. ... Note that the array was initially a sparse array with no assigned indices.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript create array of length
How to Create Array of Specific Length in JavaScript | Delft Stack
February 2, 2024 - Another way of creating an array of specific lengths is to use the map() method in JavaScript. Here, the Array(5) constructor will create an empty array of length 5. This is similar to what we saw previously.
🌐
Medium
medium.com › @ryan_forrester_ › empty-arrays-in-javascript-how-to-guide-f8643da412c2
Empty Arrays in JavaScript (How to Guide) | by ryan | Medium
October 30, 2024 - The simplest way to create an empty ... [] If you need an array of a specific length but with empty slots, you can pass a number to the Array constructor....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › Array
Array() constructor - JavaScript - MDN Web Docs
const arrayEmpty = new Array(2); console.log(arrayEmpty.length); // 2 console.log(arrayEmpty[0]); // undefined; actually, it is an empty slot console.log(0 in arrayEmpty); // false console.log(1 in arrayEmpty); // false ... const arrayOfOne = new Array("2"); // Not the number 2 but the string ...
🌐
GeeksforGeeks
geeksforgeeks.org › create-an-array-of-given-size-in-javascript
Create an Array of Given Size in JavaScript | GeeksforGeeks
We can initialize an array of certain length just by passing a single integer argument to the JavaScript array constructor. This will create an array of the given size with undefined values.Syntaxcosnt arr = new Array( length );J
Published: November 11, 2024
🌐
Just Academy
justacademy.co › blog-detail › how-to-declare-empty-array-in-javascript
How to Declare Empty Array in JavaScript by Roshan Chaturvedi | JustAcademy
April 23, 2024 - How to Declare Empty Array in JavaScriptIn JavaScript, declaring an empty array is done simply by using empty square brackets `[]`. This is useful when you need to initialize a variable that will store a collection of elements but doesn't have ...
🌐
Altcademy
altcademy.com › blog › how-to-create-an-empty-array-in-javascript
How to create an empty array in JavaScript - Altcademy.com
August 24, 2023 - An empty array is an array that does not contain any elements. It's like a shopping list you haven't written anything on yet, or a bookshelf you've just bought and haven't put any books on. To create an empty array in JavaScript, you can use the following syntax: ... In this example, emptyArray is an array with no items.