- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create empty array of a given size in JavaScript
To create an empty array of given size, use the new operator −
var numberArray = new Array(10);
After that, let’s set some values in the array. Following is the code −
Example
var numberArray = new Array(10); console.log("The length="+numberArray.length) numberArray=[10,20,30,40,50,60]; console.log("The array value="); for(var i=0;i<numberArray.length;i++) console.log(numberArray[i]);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo52.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo52.js The length=10 The array value= 10 20 30 40 50 60
- Related Articles
- How to create an empty array in Kotlin?
- No. of ways to empty an array in JavaScript
- How to empty an array in JavaScript?
- In Javascript how to empty an array
- How to create Empty Values String in JavaScript?
- Creating a binary spiral array of specific size in JavaScript
- How to create permutation of array with the given number of elements in JavaScript
- C# program to create an empty string array
- How do I empty an array in JavaScript?
- JavaScript to push value in empty index in array
- Removing all the empty indices from array in JavaScript
- Find maximum of minimum for every window size in a given array in C++
- Python program to reverse an array in groups of given size?
- Java program to reverse an array in groups of given size
- Print all possible combinations of r elements in a given array of size n in C++

Advertisements