DEV Community

Cover image for Different Ways to Create Arrays
Arun Kumar G
Arun Kumar G

Posted on

Different Ways to Create Arrays

In JavaScript arrays are very important data structures one has to learn and good to be master at after learning the language basics, here in this article I would like to cover the ways to create them and arrays are common and comes handy to solve manythings

Array literal Syntax

 const arr_name  = [];   // array without a size
 const arra_name = [5];  // with size 5 elements
Enter fullscreen mode Exit fullscreen mode

Literal syntax is the easy one to create,
Its most often used by developers to create arrays
supports other array operations

Array using constructor method

 const arr_name = new Array();  // Array is the constructor
 const arr_name = new Array(5);  // Create array with 5 elements
Enter fullscreen mode Exit fullscreen mode

Top comments (0)