- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Creating Arrays using Javascript
There are many ways to create an Array in JavaScript. We'll look at how to create an empty array first using 2 methods.
let myArr = []; let myArr = new Array();
Both of the above lines create an empty array. The JavaScript community always prefers the first method as it is easier to read, type and performs the same task as the second one. You can also populate the array when you're creating it using either of the following 2 notations −
let myArr = ["Mon", "Tue", "Wed", "Thu", "Fri"]; let myArr = new Array("Mon", "Tue", "Wed", "Thu", "Fri");
You can print it on the console using a console.log statement. For example,
console.log(myArr);
This will give the output.
["Mon", "Tue", "Wed", "Thu", "Fri"]
Though not used much, you can also create an array by specifying its length as follows −
let myArr = new Array(5);
This will create an array of size 5.
- Related Articles
- Creating Dictionary using Javascript
- Creating a Set using Javascript
- Creating a BinaryTree using Javascript
- Creating a Priority Queue using Javascript
- Creating a linked list using Javascript
- Creating a hash table using Javascript
- Creating a Doubly Linked List using Javascript
- Creating JavaScript constructor using the “new” operator?
- Creating auto-resize text area using JavaScript
- Compare arrays using Array.prototype.every() in JavaScript
- Creating Animated Counter using HTML, CSS, and JavaScript
- How to transform JavaScript arrays using maps?
- Sorting arrays using bubble sort in JavaScript
- Creating a Simple Calculator using HTML, CSS, and JavaScript
- Creating a Dynamic Report Card using HTML, CSS, and JavaScript

Advertisements